cxf spring 简单的搭建服务端

下载cxf官方包 lib文件夹里有一个 WHICH_JARS  按照这个说明导入相应的包

首先在spring application.xml里面 加上

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:cache="http://www.springframework.org/schema/cache" xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-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/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd"

>
<import resource="classpath:/cxf/cxf.xml"/>
<import resource="classpath:/cxf/cxf-extension-soap.xml"/>
<import resource="classpath:/cxf/cxf-servlet.xml"/>

 蓝色的地方为必须添加的地方 


下面是cxf-servlet.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" xmlns:soap="http://cxf.apache.org/bindings/soap" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<jaxws:server id="userService" serviceClass="lc.item.cxf.UserService" address="/user">
<jaxws:serviceBean>
<bean class="lc.item.cxf.UserServiceImpl"/>
</jaxws:serviceBean>
</jaxws:server>
</beans>

其余2个xml都可以在jar里面找到然后 复制出来

cxf.xml 在cxf-core MATE-INF > cxf 下面

cxf-extension-soap.xml 在 cxf-rt-frontend-jaxws MATE-INF > cxf 下面


接下来是在web.xml里面配置

<!-- cxf -->
<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>/ws/*</url-pattern>
</servlet-mapping>

然后开始写接口类

package lc.item.cxf;

import javax.jws.WebParam;
import javax.jws.WebService;

import lc.item.sys.entity.User;

@WebService
public interface UserService {

public User getUser(@WebParam(name = "userId")Long userId);
}


package lc.item.cxf;

import javax.jws.WebMethod;
import javax.jws.WebService;

import lc.item.cxf.UserService;
import lc.item.sys.entity.User;

@WebService(endpointInterface="lc.item.cxf.UserService",serviceName="userService")
public class UserServiceImpl implements UserService{

public User getUser(Long userId) {
System.out.println(userId);
User user = new User();
user.setId(1001L);
user.setUsername("张三");
user.setEmail("dongwq@qq.com");
return user;
}
}


这2个类写好了以后  就可以访问  地址 http://127.0.0.1:8080/item/ws/

注:路劲里的ws 是在web.xml里面配置的

访问显示

下面继续访问  http://127.0.0.1:8080/item/ws/user?wsdl

路径里面的 user 是在cxf-servlet.xml 里面配置的那个 address


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值