1,导入jar 包
<!-- cxf -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-api</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-bindings-soap</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-security</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.3</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore-nio</artifactId>
<version>4.3</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<version>4.0-beta4</version>
</dependency>
<!-- cxf -->
2.写接口
package com.sharp.hibernatedemo.ws;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import com.sharp.hibernatedemo.domain.User;
@WebService
@SOAPBinding(style = SOAPBinding.Style.RPC, use = SOAPBinding.Use.LITERAL)
public interface IUserServiceWs
{
void addUser(User user);
}
3.写实现类
package com.sharp.hibernatedemo.ws.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.sharp.hibernatedemo.domain.User;
import com.sharp.hibernatedemo.service.IUserService;
import com.sharp.hibernatedemo.ws.IUserServiceWs;
@Component("userServiceWs")
public class UserServiceWsImpl implements IUserServiceWs
{
@Autowired
private IUserService userService;
public void addUser(User user)
{
userService.addUser(user);
}
}
4.配置spring-ws.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:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.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:server id="userServiceWss"
serviceClass="com.sharp.hibernatedemo.ws.IUserServiceWs"
address="/userServiceWs">
<jaxws:serviceBean>
<ref bean="userServiceWs" /> <!-- 和上面的id名字一定不要重复了 -->
</jaxws:serviceBean>
</jaxws:server>
</beans>
需要注意的namespace
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
[b]xmlns:jaxws="http://cxf.apache.org/jaxws" [/b]
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:http-conf = "http://cxf.apache.org/transports/http/configuration"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
[b] http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd[/b]
http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.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>
分享到:
相关推荐
使用cxf+spring框架开发webservice的客户端与服务端代码,用于连接两个项目
图片 文档、音视频上传下载,可供学习使用
绝对可运行,里面有客户端和服务端还有对应的操作文档,导入eclipse或者MyEclipse十分钟内就搞定,虽然贵点但是绝对物有所值.
使用cxf和spring开发基于https的webservice服务端以及客户端样例
自己用做项目时用到CXF整合Spring,写了下步骤,希望能帮到有需要的人!
CXF开发webservice服务端,希望对大家有所帮助
webserivce.、cxf整合spring,用的是spring3和cxf3。欢迎大家下载尝试
针对目前网上的很多cxf相关的服务开发源码不能使用,自己做的cxf与spring的整合,里面包含了服务端和客户端代码,还有说明文档,这个demo使用的是cxf的服务端,axis2的客户端,希望能够帮到cxf初学者们。
ibatis+spring+cxf+mysql搭建webservice的服务端,文章地址在http://blog.csdn.net/cenyi2013/article/details/17315755
cxf客户端调用axis服务端流程
cxf+spring实现webservice
cxf 与 Spring 结合,此例子中包含服务端和客户端, 2个工程都是与SSH 结合使用。相信对刚接触的朋友有用!
以前做java的初步理解了下...实现了3个接口服务,1个接口服务端提供登录是用的传统webservice,用的cxf。1个接口只是测试,测试了双向json数据传输解析。还一个接口是网络上提供的手机归属地查询,实现了它的接口。
内容为CXF整合spring的服务端和客户端开发例子,注释不太详尽,网上的教程比较多,但是多跑不起来,特地把整个工程都打包给大家做参考,程序内容均来自网上整理,均可以运行。
web项目使用spring和cxf的一个开发实例,有简单的代码样例和jar。是一个完整的项目,最终发布完成时访问 http://ip:port/项目名称/webservices/ 就会发现你发布的webservice服务。
使用cxf和spring开发基于https的webservice服务端以及客户端样例源码.rar
CXF&spring实例,服务端客户调,spring配置
WebService的CXF整合Spring有源码和jar包
CXF+spring+struts实现WebService