(七) CXF 整合Spring--发布WS服务
来源:互联网 发布:数控车床编程g代码 编辑:程序博客网 时间:2024/05/17 11:08
CXF 可以轻松整合Spring 来发布WS服务。
【1. 引入相关jar 包】
CXF 使用在WEB项目中,所以就不需要引入 jetty 的相关jar包了,只需要引入以下几个包即可:
引入spring 的相关jar 包,最终引入包结构:
【2. 配置web.xml】
1. 配置spring 配置文件路径
2. 配置spring 监听
3. 配置log4j 日志框架
4. 配置CXF 拦截器
<?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_3_0.xsd"id="WebApp_ID" version="3.0"><!-- 配置spring 配置文件路径 --><context-param><param-name>contextConfigLocation</param-name><param-value>classpath*:config/spring-*.xml</param-value></context-param><!-- 配置spring 监听器,监听spring 启动 --><listener><listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class></listener><!-- 指定log4j 日志 --><context-param><param-name>log4jConfigLocation</param-name><param-value>classpath:config/log4j.xml</param-value></context-param><context-param><param-name>log4jRefreshInterval</param-name><param-value>60000</param-value></context-param><listener><listener-class>org.springframework.web.util.Log4jConfigListener</listener-class></listener><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener> <!-- 所有请求都会先经过cxf框架 --> <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>/*</url-pattern> </servlet-mapping></web-app>
【3. 配置spring-cxf.xml】
1. 引入CXF 默认配置
2. 配置要发布的WS服务
<?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"><!-- 引入CXF 相关配置 --><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="loggingInInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor" /><!-- 配置日志出拦截器 --><bean id="loggingOutInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor" /><!--implementor:指定接口具体实现类,address:随意配 --><jaxws:endpoint id="helloWorldWS" implementor="org.zgf.cxf.spring.ws.HelloWordWS" address="/HelloWorld"><!-- 输入日志拦截器 ,多个日志拦截器按顺序写即可--><jaxws:inInterceptors><ref bean="loggingInInterceptor" /><!-- 也可使用匿名Bean方式配置 <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" />--></jaxws:inInterceptors><!-- 输出日志拦截器 --><jaxws:outInterceptors><ref bean="loggingOutInterceptor" /></jaxws:outInterceptors></jaxws:endpoint></beans>
【4. 启动web 服务】
启动web 服务,在浏览器中输入http://ip:port/projectname (http://localhost:8888/CXF-spring/)可以看到如下页面
【5. 客户端测试】
客户端测试可参看《(三)CXF客户端调用WS服务》
【6. 总结】
1. 服务器端配置也可以使用<cxf:bus> 标签做全局配置,配置拦截器,详细用法参看《(八)CXF整合spring--调用WS服务》
2. CXF应用于WEB项目中,导入jar包时,不需要引入jettry的相关jar包,同样在开启GZIP的时候也不用靠CXF来开启, 而是依赖于部署的服务器。 如果WEB服务器开启了GZIP 那么, 如果配置的压缩条件包含text/xml 的话,那么就会自动压缩,因为WS服务返回的内容格式为:Content-Type--text/xml;charset=UTF-8。
3. 源代码下载:《CXF-spring-server.zip》
- (七) CXF 整合Spring--发布WS服务
- (八) CXF 整合Spring--调用WS服务
- (二) CXF 发布WS服务
- (四)CXF整合Spring发布WebService服务
- Spring整合CXF之发布WebService服务
- Spring整合CXF之发布WebService服务
- Spring整合CXF之发布WebService服务
- Spring整合CXF配置WebService服务发布
- Spring整合CXF之发布WebService服务
- spring boot整合cxf发布webservice服务和spring boot整合cxf客户端调用webservice服务
- WS之cxf与spring整合1
- WS之cxf与spring整合2
- (五)CXF整合Spring发布RESTful风格的Web服务
- 7、CXF与Spring整合,发布WebService服务
- webservice--CXF+Spring整合发布SOAP协议的服务
- webservice--CXF+Spring整合发布REST的服务
- 9.Web Service Spring整合CXF之发布服务
- 使用cxf发布rest服务接口,和spring的整合
- Native Socket.IO and Android demo
- Android开发常用命令整理
- 杭电oj 2004 成绩转换
- 蓝牙笔和手机通过蓝牙协议的通讯
- 剑指offer-二叉搜索树的后序遍历序列
- (七) CXF 整合Spring--发布WS服务
- JDBC常用类和接口
- 在 UITableView 上加手势(UITableView上点击键盘消失)
- 功能块网站推荐
- win7 Embedded EWF与HORM特性(实战验证)
- 理解Swift中map 和 flatMap对集合的作用
- 三角形面积
- (八) CXF 整合Spring--调用WS服务
- Email--Send