简单CXF3.0整合Spring4.1

之前写过一个CXF整合Spring,那是的CXF是2.2的,Spring是3.2的,前些日子去CXF官网下了个3.1的,用Spring4.3的整合,发现用旧版本配置的方式来配置新版的已不管用了,这两天又在网上搜了CXF3.0和Spring4的整合方式,原来使用的包都变了,这又重新整理一份,真麻烦。

 

接口

 

package test;


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


@WebService
public interface Hello {
public String say(@WebParam(name="name")String name);
}


实现

 

 

package test;

import javax.jws.WebService;

@WebService(endpointInterface="test.Hello")
public class HelloImp implements Hello {

	public String say(String name) {
		return "hello,"+name;
	}

}


bean.xml(或applicationContext.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:context="http://www.springframework.org/schema/context" 
       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://www.springframework.org/schema/context  
                            http://www.springframework.org/schema/aop/spring-context.xsd
                            http://cxf.apache.org/jaxws 
                            http://cxf.apache.org/schemas/jaxws.xsd">
    <import resource="classpath:META-INF/cxf/cxf.xml"/>
    <jaxws:endpoint id="abc" address="/cde" implementor="test.HelloImp"></jaxws:endpoint>
    
</beans>


web.xml

 

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
                            http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         id="WebApp_ID" 
         version="3.1">
  <display-name>test</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  
  <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>
  
  <listener>
   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  
  <context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>classpath:bean.xml</param-value>
  </context-param>
  
</web-app>

 

 

 

 

 

使用的包(缺一不可)

Center

 

访问URL:http://localhost:8080/test/service/cde?wsdl

 

生成客户端命令:wsdl2java -client -p client -d e:/ http://localhost:8080/test/service/cde?wsdl

把生成的客户端放入到项目里,直接运行其中xxxxxxx_Client.java类,即可看到运行结果。

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

简单就好-怒

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值