CXF webService 与 SpringMVC 整合要点
来源:互联网 发布:网络经营许可证公示 编辑:程序博客网 时间:2024/06/14 17:39
1.准备cxf的jar包
如果没有的话可以访问,链接:http://pan.baidu.com/s/1cCi9g6
2.在web.xml中配置cxf-servlet.xml
<!-- CXF和servlet整合 走一下源码就知道它会找cxf-servlet.xml文件--> <servlet> <servlet-name>cxf</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> <init-param> <param-name>config-location</param-name> <param-value>classpath:cxf-servlet.xml</param-value> </init-param> </servlet> <servlet-mapping> <!-- 访问WSDL文件的时候就需要访问这个名字,通过它可以找到web服务 --> <servlet-name>cxf</servlet-name> <url-pattern>/webService/*</url-pattern> </servlet-mapping>
3.cxf-servlet.xml中配置 webServcie 的 spring-webService.xml的bean
<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"> <import resource="classpath:META-INF/cxf/cxf.xml"/> <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/> <jaxws:endpoint implementor="#WeChatService" address="/weChat"/> <import resource="spring-webService.xml"/></beans>
4.spring-webService.xml注入service属性
<?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:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="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/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> <bean id="WeChatService" class="com.webService.WeChatService"></bean></beans>
5.为com.webService.WeChatService添加注解
@WebService(serviceName="WeChatService")public class WeChatService { public void function1(){ ......... }}
6.用web服务器,如tomcat发布访问
http://localhost:8080/ws/webService/weChat?wsdl
7.生成client文件,如
wsimport -s D:\\workspaces\\MyEclipse\\ws1Client\\src -p com.web.client.eeams -keep http://localhost:8080/ws/webService/weChat?wsdl
特别注意:CXF在做webServices复杂对象传递时,返回值的类型不要用接口类型。例如(List 应该换成ArrayList ,Map应该换成HashMap),还有就是ArrayList<HashMap<Sting,Object>>
也是cxf无法解析的,他会报list canot cast to a hashMap
建议使用 List<包装对象>来返回复杂类型。
阅读全文
0 0
- CXF webService 与 SpringMVC 整合要点
- SpringMVC整合CXF开发WebService
- 一、CXF与springMVC整合的webService发布
- 二、CXF与springMVC整合的webService客户端调用
- webservice-cxf-与spring整合
- WebService -Spring与CXF整合
- WebService之CXF与Spring的整合
- CXF与Spring整合开发WebService服务
- WebService cxf 与 ssm框架的整合
- 整合spring与cxf,利用cxf编写webservice
- 整合spring与cxf,利用cxf编写webservice
- WebService(3)cxf webService与Spring整合
- CXF WebService整合Spring
- CXF WebService整合Spring
- CXF WebService整合Spring
- CXF WebService整合Spring
- CXF WebService整合Spring
- CXF WebService整合Spring
- 【Hbase异常】windows 中使用hbase 异常:java.io.IOException: Could not locate executable null\bin\winutils.exe
- Python基础概念_6_模块
- Eclipse背景颜色修改
- Linux中eval命令
- canvas画出五角星
- CXF webService 与 SpringMVC 整合要点
- Python爬取百度图片
- 首传
- java知识点小结(一)
- 浏览器模拟网站browserling
- hihocoder p1077 线段树
- Environment一些方法的测试
- 数据结构BinaryTree实例(一):先序遍历二叉树(递归与非递归)
- SaltStack实战之配置管理-状态间关系