cxf+Spring.搭建简单的webservice

开发工具:eclipse3.5

数据库:mysql5

框架:

  1. spring2.5.5
  2. cxf2.2.6

整合步骤:


cxf与spring的整合十分方便.cxf的lib中就内置了spring的支持.cxf2.2.6中包含的spring包为2.5.6版本.但是想用自己的spring也可以,在导入cxf包的时候不导入spring的包就可以了.
spring,直接导入spring.jar 就可以了,方便起见.
到这一步就可以开始测试是否整合成功.

spring的配置文件.
<?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:simple="http://cxf.apache.org/simple"
xmlns:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd
http://cxf.apache.org/simple http://cxf.apache.org/schemas/simple.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>

web.xml配置文件:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/applicationContext.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern> /service/*</url-pattern> 
</servlet-mapping>

*红色部分的路径会影响生成webservice的路径

写测试类:
@WebService
public interface ILoginService {
 @WebMethod
 public int login(@WebParam(name = "username") String username,
   @WebParam(name = "passwords") String password);
}
发布: 在spring中发布webservice
<bean id="loginService" class="com.wks.webservice.impl.LoginService"></bean>
 <jaxws:endpoint implementor="#loginService" address="/login">
 </jaxws:endpoint>
最后就可以根据地址测试了. 发布成功.
Spring 和 cxf的整合就完成了.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值