前言:因为通常情况下,我们都是用Spring来整合其它框架,所以这里我们不在一、二的基础上进行操作,而是新建一个工程,然后拷贝src下的java代码和db.properties文件到新的工程中,再添加jar。
1:导入spring的jar,这里闲麻烦,把3.1的dist里面的jar都导进来了,在导入cxf的jar如下:
spring的jar这里就不展示了
2:建立beans.xml文件,保存在src下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.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"/>
<bean id="userSerivce" class="org.wjlmgqs.service.imp.UserServiceImp"/>
<jaxws:server id="userWebService" serviceClass="org.wjlmgqs.service.UserService" address="/user">
<jaxws:serviceBean>
<ref bean="userSerivce"/>
</jaxws:serviceBean>
<!--
<jaxws:inInterceptors>
<ref bean="inMessageInterceptor"/>
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<ref bean="outLoggingInterceptor"/>
</jaxws:outInterceptors>
-->
</jaxws:server>
<!-- 上面通过jaxws:server来发布服务,还可以通过下面的方式实现
<bean id="userSerivce" class="org.wjlmgqs.service.imp.UserServiceImp"/>
<jaxws:endpoint id="userWebService" implementor="#userSerivce" address="/user"/>
-->
</beans>
3:修改web.xml,如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:beans.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</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>/webservice/*</url-pattern>
</servlet-mapping>
</web-app>
4:浏览器访问:http://localhost:8080/SpringWebService/webservice/user?wsdl
结果同WebService认识二一样
该工程源码下载:下载源码