您的位置:首页 > 编程语言 > Java开发

CXF 在Spring中开发服务端步骤

2013-10-10 17:37 141 查看
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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: