CXF3.1.6+Spring4.1.9整合
来源:互联网 发布:质量软件 编辑:程序博客网 时间:2024/05/20 05:23
开发中经常碰到不同项目之间需要相互调用项目中已经成熟的方法来进行开发的情况。
这时候我选择的是WebService进行开发。由于之前调用WebService时使用过CXF这个框架,所以这次就继续选择了CXF来进行开发。
这里值得说明的是,我之前使用的是Spring3.1进行开发,所以想着直接整合进CXF3.1,在进行了两天的尝试无果后终于发现,原来需要高版本的Spring才能兼容CXF3.1.6,否则会报错,报的错误貌似是Spring3.1中的Core包中找不到ClassUtils.class中的isCglibProxyClass(Class<?>)方法,我在替换成Spring4.1后就解决了.
这里简单说一下Spring4.1与CXF3.1.6进行整合中简单的步骤及相关配置。
一、编写WebService接口类及其实现类
package WebService.IWebService;import java.util.List;import javax.jws.WebParam;import javax.jws.WebService;import WebService.Polo.TelnetCommand;import WebService.Polo.TelnetCommandResult;@WebServicepublic interface ITestWebService {public List<TelnetCommandResult> sayHi(@WebParam(name="telnetCommandList") List<TelnetCommand> telnetCommandList);}
这里需要说明@WebParam(name="telnetCommandList") 最好是编写上去,虽然不编写也不影响使用,但是在WSDL中将只能看到arg1、arg2等的参数名而不是具体参数名,影响接口的可读性。
@WebService也需要注明,否则调用时会报找不到相关接口的错误。
二、配置web.xml
<!--spring监听 --> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <!--CXF配置 --> <servlet> <servlet-name>CXFService</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>CXFService</servlet-name> <url-pattern>/SDDataWebService/*</url-pattern> </servlet-mapping>
需要在web.xml中加入上述配置,在tomcat启动时启用CXF服务,这里贴出的是最低配置,在这里还可以加入其他配置,暂不说明。
三、配置applicationContext.xml
<?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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-2.5.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-2.5.xsd"><!--配置CXF扫描,并制定包目录 --><context:component-scan base-package="WebService"></context:component-scan><import resource="applicationContext-cxf.xml"/>
需要在applicationContext.xml中加入上述配置,这里是指定了扫描的包路径以及将有关CXF的配置分离出来并制定配置文件的位置。
四、配置applicationContext-cxf.xml
<?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/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <bean id="testService" class="WebService.WebServiceImpl.TestServiceImpl"/> <!--測試Service --><jaxws:server serviceClass="WebService.IWebService.ITestWebService" address="/test"><jaxws:serviceBean><ref bean="testService"/></jaxws:serviceBean></jaxws:server></beans>
这里将有关CXF的配置从applicationContext.xml中分离出来,避免applicationContext.xml太过复杂,难以读懂。这里需要特别注意CXF所需生命的命名空间以及。
五、到这里就可以运行tomcat并访问http://localhost:8080/项目名称/SDDataWebService ,可以看到WebService有没有运行成功。
访问http://localhost:8080/项目名称/SDDataWebService/test?wsdl可以看到WebService的wsdl文件。
- CXF3.1.6+Spring4.1.9整合
- 简单CXF3.0整合Spring4.1
- spring4.x + cxf3.x整合实例
- WebService Spring4.3+cxf3.1.5整合Demo
- cxf3.1.4整合spring4.1.7 demo-xs
- 手把手教你 cxf3.1.4整合spring4.2
- [CXF REST标准实战系列] 二、Spring4.0 整合 CXF3.0,实现测试接口
- 转载 [CXF REST标准实战系列] 二、Spring4.0 整合 CXF3.0,实现测试接口
- cxf3.0+spring4.0.5错误
- spring4.1.6+cxf3.0.8的简单WebService案例(maven工程)
- CXF3+spring4发布RESTful问题总结
- 利用cxf3.14+spring4.2发布webservice
- 使用 Spring4 + CXF3 + WS-Security 开发 WebService
- Spring 4.*和CXF3.*整合
- spring4.1.6整合hibernate4.0
- spring4.1.6整合Struts2.5.5
- Spring4--Spring4整合mybatis3
- Spring整合CXF3.1实现webservice
- JSON格式数据分析
- 排序函数模板 冒泡法
- 准确率与召回率
- 类的加载
- Spring 基础知识学习
- CXF3.1.6+Spring4.1.9整合
- 常见网络端口及其服务
- JAVA中的static -静态变量-静态方法-静态初始化块
- 计费系统学习之路之错误笔记day07
- Datatable删除行的Delete和Remove方法
- ubuntu/linux下命令行安装jdk
- 148. Sort List
- 紫书_第八章_高效算法设计_8.3.2——循环日程表问题
- HDU2072 单词数(解法二)