CXF实现和Spring整合发布WebService
2012-07-30 10:20
603 查看
这些天项目框架升级..........................必须学习CXF进行发布WebService.............................那么必不可少的就是和Spring整合
1..................................首先创建Web工程SpringCXF
2.................................导入必须的架包(本人尝试了一下需找最低配置,至少需要的架包如下,你可以直接把apache-cxf-2.6.1下lib包直接copy到项目lib目录下,一定OK,呵呵)
![](http://my.csdn.net/uploads/201207/30/1343609151_5484.gif)
3............................下一步要进行Web.xml的配置,来通过servlet进行Spring的过滤,从而能够查找到发布的接口
web.xml
4.....................................在src目录下新建applicationContext-server.xml文件,用来进行Spring映射,并添加与CXF整合配置
5..................................编写接口类并添加CXF注解
6..................................编写接口实现类同时加上CXF注解
7.................................配置Spring映射文件,
8............................启动服务器进行发布部署,在浏览器中输入http://localhost:8080/SpringCXF/services/userService?wsdl,显示如下结果
![](http://my.csdn.net/uploads/201207/30/1343615419_7194.gif)
9...........................发布成功。
1..................................首先创建Web工程SpringCXF
2.................................导入必须的架包(本人尝试了一下需找最低配置,至少需要的架包如下,你可以直接把apache-cxf-2.6.1下lib包直接copy到项目lib目录下,一定OK,呵呵)
![](http://my.csdn.net/uploads/201207/30/1343609151_5484.gif)
3............................下一步要进行Web.xml的配置,来通过servlet进行Spring的过滤,从而能够查找到发布的接口
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <!--spring需要加载的配置文件--> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:applicationContext-server.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- cxf服务启动servlet --> <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>/services/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
4.....................................在src目录下新建applicationContext-server.xml文件,用来进行Spring映射,并添加与CXF整合配置
<?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" /> </beans>
5..................................编写接口类并添加CXF注解
package com; import javax.jws.WebParam; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Style; @WebService @SOAPBinding(style = Style.RPC) public interface IComplexUserService { public String getUserByName(@WebParam(name = "username") String username); public void setUser(String username); }
6..................................编写接口实现类同时加上CXF注解
package com; import javax.jws.WebParam; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Style; @WebService @SOAPBinding(style = Style.RPC) @SuppressWarnings("deprecation") public class ComplexUserService implements IComplexUserService { public String getUserByName(@WebParam(name ="username")String username) { return "Hello:"+username; } public void setUser(String username) { System.out.println(username); } }
7.................................配置Spring映射文件,
<?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="userServiceBean" class="com.ComplexUserService" /> <jaxws:server id="userService" serviceClass="com.IComplexUserService" address="/userService"> <jaxws:serviceBean> <ref bean="userServiceBean" /> </jaxws:serviceBean> </jaxws:server> </beans>
8............................启动服务器进行发布部署,在浏览器中输入http://localhost:8080/SpringCXF/services/userService?wsdl,显示如下结果
![](http://my.csdn.net/uploads/201207/30/1343615419_7194.gif)
9...........................发布成功。
相关文章推荐
- Maven+SpringMVC+CXF整合实现webservice服务的发布与调用
- [置顶] spring整合cxf实现webservice发布
- Spring整合CXF,发布RSETful 风格WebService
- httpclient4.x调用cxf发布的webservice的某个方法(有参数,有返回值)(未整合spring)
- CXF和spring整合实现webservice实例
- Spring整合CXF发布WebService
- spring和cxf框架整合实现webService服务
- springboot整合cxf发布webservice以及调用的方法
- 8、CXF与Spring整合发布http rest 风格的WebService服务
- Spring整合CXF步骤,Spring实现webService,spring整合WebService
- Spring整合CXF 发布webservice接口服务器(普通及REST)和客户端,WSDL简单解析
- strtus2 + spring + CXF 实现能访问action的同时还能调用spring发布的Webservice
- SpringBoot整合cxf发布webService
- CXF和spring整合实现webservice实例
- Spring整合CXF,发布RSETful 风格WebService
- (四)CXF整合Spring发布WebService服务
- WebService(CXF发布WebService服务与Spring整合)(2)
- webservice--CXF+Spring整合发布SOAP协议的服务
- cxf整合spring发布webservice
- Spring整合CXF配置WebService服务发布