1.服务端
1.1 创建web工程
1.2 引入jar包
1.3 在web.xml中配置cxfServlet,并引入cxf配置文件
<servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<init-param>
<param-name>config-location</param-name>
<param-value>classpath:cxf.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
1.4 在classpath下配置cxf.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"
xmlns:soap="http://cxf.apache.org/bindings/soap"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/bindings/soap
http://cxf.apache.org/schemas/configuration/soap.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<!-- 引入CXF Bean定义如下,早期的版本中使用 -->
<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" />
<bean id="MyServcie" class="MyServiceImpl"/>
<!-- 注册服务 -->
<jaxws:server id="myService" address="/cxfService">
<jaxws:serviceBean>
<ref bean="MyServcie"/>
</jaxws:serviceBean>
</jaxws:server>
</beans>
1.4 创建interface接口,并创建实现类,启动服务器发布发布服务
2.客户端
2.1 创建工程
2.1.1 引入jar包
2.2 调用java的wsimport或cxf的我受到了wsdl2java 解析wsdl的xml文件生成类
2.3 复制接口到创建的工程
2.4 配置cxf.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"
xmlns:soap="http://cxf.apache.org/bindings/soap"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/bindings/soap
http://cxf.apache.org/schemas/configuration/soap.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<!-- 引入CXF Bean定义如下,早期的版本中使用 -->
<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" />
<!-- 注册CXF客户端代理对象,通过spring框架创建这个代理对象,使用代理对象实现远程调用 -->
<jaxws:client id="myClient"
address="http://127.20.10.3:8080/cxfServerTets/service/cxfService"
serviceClass="MyServcie">
</jaxws:client>
</beans>
2.5 启动工程,加载cxf.xml文件,获取接口实现类,调用服务.
ApplicationContext ac = new ClassPathXmlApplicationContext("cxf.xml");
MyServcie ms = (MyServcie) ac.getBean("myClient");
String a = ms.sayHello("yangyang", 30);
System.out.println(a);