一、相关基础内容
参见:WebService(CXF对外发布WebService服务)(1)
二、与Spring整合
1、Spring配置文件
在src/main/resources目录下新建webService.xml文件,内容如下(注意:这里引入的cxf.xml等文件是存在于cxf-core.jar中的,只要工程引入了cxf等一系列的jar包,这里就会加载到):
<?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:p="http://www.springframework.org/schema/p"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.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" />
<!-- services接口配置 -->
<bean id="WebServiceImpl" class="com.cah.ddi3.ws.WebServiceImpl"></bean>
<!-- CXF 配置WebServices的服务名及访问地址 -->
<jaxws:server id="WService" address="/WService" serviceClass="com.cah.ddi3.ws.WebServiceI">
<jaxws:serviceBean>
<ref bean="WebServiceImpl"/>
</jaxws:serviceBean>
</jaxws:server>
</beans>
2、web.xml配置
配置加载webService.xml文件
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:webService.xml</param-value>
</context-param>
配置cxf servlet
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXFServlet</display-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/<工程名>/ws,呈现如下页面,表明发布成功: