maven项目配置http://cxf.apache.org/docs/using-cxf-with-maven.html

<properties>
<cxf.version>2.2.3</cxf.version>
</properties> <dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<!-- Jetty is needed if you're are not using the CXFServlet -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>

项目所需jar包:http://files.cnblogs.com/files/walk-the-Line/cxf-spirng.zip

首先写一个demo接口

package cn.cxf.demo;

import javax.jws.WebService;

@WebService
public interface Demo {
String sayHi(String text);
}

然后就需要它的实现类

targetNamespace 是指向接口的包路径

package cn.cxf.demo.impl;

import javax.jws.WebService;

import cn.cxf.demo.Demo;
@WebService(endpointInterface="cn.cxf.demo.Demo", serviceName="DemoService", targetNamespace="http://demo.cxf.cn/")
public class DemoImpl implements Demo { @Override
public String sayHi(String text) {
return "Hi ! " + text;
} }

在src目录下添加applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <!-- 测试接口 -->
<jaxws:endpoint id="demoService"
implementor="cn.cxf.demo.impl.DemoImpl"
address="/DemoService" /> </beans>

再修改下web.xml文件就搞定了~(在web.xml添加如下内容就可以了)

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>

发布一下,访问 http://localhost:8080/cxfdemo/ws 就可以看到接口已经发布成功了。

调用接口就更简单了

如果只是单纯的调用接口的话只需要4个jar包就可以了:

cxf-2.4.3.jar

neethi-3.0.1.jar

wsdl4j-1.6.2.jar

xmlschema-core-2.0.1.jar

可以从上面的jar包里挑选。

调用代码如下:

package cn.cxf.test;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory; public class CXFWSTest {
public static void main(String[] args) throws Exception {
JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
Client client = factory.createClient("http://localhost:8080/cxfdemo/ws/DemoService?wsdl");
Object[] objs = client.invoke("sayHi", "阿福");
System.out.println(objs[0].toString());
}
}

最新文章

  1. C# 如何提取SaveFileDialog的保存路径
  2. [教学] Delphi Berlin 10.1 开发 Windows 10 平板 App 远程调试
  3. poj1703_Find them, Catch them_并查集
  4. angular $scope对象
  5. Could not load type from string value 'DALMSSQL.DBSessionFactory,DALMSSQL'.
  6. Winform 获取当前单击的控件名称 和 向窗体添加控件
  7. BZOJ4607 : [PA2015 Final]Edycja
  8. 如何去设计一个自适应的网页设计或HTMl5
  9. mybatis实战
  10. JPA学习---第十一节:JPA中的多对多双向关联实体定义与注解设置及操作
  11. C# 使用winForm的TreeView显示中国城镇四级联动
  12. 从实践谈iOS生命周期
  13. HDU SPFA算法 Invitation Cards
  14. 【集美大学1411_助教博客】团队作业1——团队展示&amp;选题 成绩
  15. showmemory.c 和 hello.s 源码
  16. Atomic in Redis
  17. 在linux系统下安装配置apacheserver
  18. android-----带你一步一步优化ListView(一)
  19. Kattis之旅——Factovisors
  20. MyBatis打印输出SQL语句

热门文章

  1. HBase 增删改查Java API
  2. PostgreSQL 数据库升级
  3. VectorDrawable在Android中的配置
  4. MySQL高可用之PXC安装部署(续)
  5. 「暑期训练」「Brute Force」 Money Transfers (CFR353D2C)
  6. 【紫书】(UVa12563)Jin Ge Jin Qu hao
  7. CS229 1
  8. SQL - SELECT COUNT用法
  9. linux 进程间通信之pipe
  10. 【bzoj4750】密码安全 单调栈