Spring整合CXF之发布WebService服务
来源:互联网 发布:在淘宝怎么搜索精仿鞋 编辑:程序博客网 时间:2024/05/18 12:43
根据官方文档。我们把前面的实例用Spring整合CXF来处理下。会简化很多;
首先我们来建一个Maven项目 WebService_CXF
建好项目第一步,我们打开pom.xml
<!-- 添加Spring支持 --><dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>4.1.7.RELEASE</version></dependency><dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>4.1.7.RELEASE</version></dependency><dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>4.1.7.RELEASE</version> </dependency><dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.1.7.RELEASE</version></dependency><dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>4.1.7.RELEASE</version></dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>4.1.7.RELEASE</version></dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>4.1.7.RELEASE</version></dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>4.1.7.RELEASE</version></dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>4.1.7.RELEASE</version></dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>4.1.7.RELEASE</version></dependency><!-- 添加cxf支持 --><dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-core</artifactId> <version>3.1.5</version></dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>3.1.5</version></dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http</artifactId> <version>3.1.5</version></dependency>
我们在项目source里添加下 applicationContext.xml spring配置文件
<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:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
然后我们再applicationContext.xml导入下cxf里的一些bean配置,参考官方文档
<import resource="classpath:META-INF/cxf/cxf.xml"/> <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
把之前类放到项目里 并且在HelloWorldImpl实现类里 加上 @Component("HelloWorld")
Spring配置文件里,我加下扫描:
<!-- 自动扫描 --><context:component-scan base-package="com.gcx.webservice" />
前面搞完后,我们在处理下web.xml文件 首先启动的时候,必须加载Spring
<!-- Spring配置文件 --><context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value></context-param> <!-- Spring监听器 --><listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>
然后我们要定义一个Servlet,主要是处理WebService请求
<servlet> <servlet-name>CXFServlet</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/webservice/*</url-pattern> </servlet-mapping>
这里的话,我们所有的 /webservice请求,都交给CXFServlet类处理
最后一步,我们在Spring配置文件里,定义下webservice接口发布
<!-- 定义服务提供者 --><jaxws:endpoint implementor="#helloWorld" address="/HelloWorld"> <!-- 添加in拦截器 --> <jaxws:inInterceptors> <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/> <bean class="com.gcx.interceptor.MyInterceptor"/> </jaxws:inInterceptors> <!-- 添加out拦截器 --> <jaxws:outInterceptors> <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/> </jaxws:outInterceptors> </jaxws:endpoint>
<?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:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.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-servlet.xml"/> <!-- 自动扫描 --><context:component-scan base-package="com.gcx.webservice" /><!-- 定义服务提供者 --><jaxws:endpoint implementor="#helloWorld" address="/HelloWorld"> <!-- 添加in拦截器 --> <jaxws:inInterceptors> <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/> <bean class="com.gcx.interceptor.MyInterceptor"/> </jaxws:inInterceptors> <!-- 添加out拦截器 --> <jaxws:outInterceptors> <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/> </jaxws:outInterceptors> </jaxws:endpoint></beans>
最后启动项目访问 http://localhost:8080/WebService_CXF/webservice/
访问具体的接口: http://localhost:8080/WebService_CXF/webservice/HelloWorld?wsdl
阅读全文
0 0
- Spring整合CXF之发布WebService服务
- Spring整合CXF之发布WebService服务
- Spring整合CXF之发布WebService服务
- Spring整合CXF之发布WebService服务
- WebService之CXF整合Spring框架发布REST服务
- (四)CXF整合Spring发布WebService服务
- Spring整合CXF配置WebService服务发布
- spring boot整合cxf发布webservice服务和spring boot整合cxf客户端调用webservice服务
- Spring整合CXF发布WebService
- cxf整合spring发布webservice
- 7、CXF与Spring整合,发布WebService服务
- webservice--CXF+Spring整合发布SOAP协议的服务
- webservice--CXF+Spring整合发布REST的服务
- spring boot整合cxf发布webservice服务和cxf客户端调用
- spring boot整合cxf发布webservice服务和cxf客户端调用
- CXF WebService 7 - Spring整合CXF,发布RSETful 风格WebService
- 9.Web Service Spring整合CXF之发布服务
- CXF实现和Spring整合发布WebService
- python3 爬虫环境准备 (一)
- 梯度提升树GBDT原理
- ps常用功能小结
- LTE学习笔记--LTE整体架构和协议架构概述
- cp覆盖时,不提示的用法
- Spring整合CXF之发布WebService服务
- Codeforces Round #420 (Div. 2) E. Okabe and El Psy Kongroo [矩阵快速幂]
- 判断单链表是否带环
- 【论文阅读】Generating Natural Answers by Incorporating Copying and Retrieving Mechanisms in Sequence-to-S
- ThreadLocall类分析
- html-css 等常用
- tcp和udp通讯协议
- xgboost原理
- JZOJ__Day 1:【普及模拟】PLES