spring和cxf整合

cxf 是一个开源的服务框架。详细介绍请看官网http://cxf.apache.org/

一、配置所需jar包

整合spring 项目使用maven 进行管理。

pom中cxf部分

<span style="white-space:pre">		</span><!-- cxf  -->
		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf-rt-frontend-jaxws</artifactId>
			<version>${cxf.version}</version>
		</dependency>
		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf-rt-transports-http</artifactId>
			<version>${cxf.version}</version>
		</dependency>
		<!-- Jetty is needed if you're are not using the CXFServlet -->
		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf-rt-transports-http-jetty</artifactId>
			<version>${cxf.version}</version>
		</dependency>
		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf-tools-common</artifactId>
			<version>${cxf.version}</version>
		</dependency>
		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf-tools-java2ws</artifactId>
			<version>${cxf.version}</version>
		</dependency>
		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf-tools-validator</artifactId>
			<version>${cxf.version}</version>
		</dependency>
		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf-tools-wsdlto-core</artifactId>
			<version>${cxf.version}</version>
		</dependency>
		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf-tools-wsdlto-databinding-jaxb</artifactId>
			<version>${cxf.version}</version>
		</dependency>


spring部分(此部分是手动添加的)




二、配置配置文件web.xml appliationContext.xml

web.xml中添加
<<span style="white-space:pre">	</span>ontext-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext.xml</param-value>
	</context-param>
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
<span style="white-space:pre">	<servlet>
<span style="white-space:pre">		</span><servlet-name>CXFServlet</servlet-name>
<span style="white-space:pre">		</span><servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<span style="white-space:pre">		</span><load-on-startup>1</load-on-startup>
<span style="white-space:pre">	</span></servlet>
<span style="white-space:pre">	</span><!-- CXFServlet Mapping -->
<span style="white-space:pre">	</span><servlet-mapping>
<span style="white-space:pre">		</span><servlet-name>CXFServlet</servlet-name>
<span style="white-space:pre">		</span><url-pattern>/services/*</url-pattern>
<span style="white-space:pre">	</span></servlet-mapping></span>

applicationContext.xml
注意标红位置,引用jaxws命名空间
    
<span style="white-space:pre">	</span><beans xmlns="http://www.springframework.org/schema/beans"
<span style="white-space:pre">		</span>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<span style="white-space:pre">		</span>xmlns:p="http://www.springframework.org/schema/p"
<span style="white-space:pre">		</span>xmlns:jaxws="http://cxf.apache.org/jaxws"</span>
<span style="white-space:pre">		</span>xsi:schemaLocation="
<span style="white-space:pre">		</span>http://www.springframework.org/schema/beans 
<span style="white-space:pre">		</span>http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
<span style="white-space:pre">		</span>http://cxf.apache.org/jaxws</span>   
<span style="white-space:pre">		</span>http://cxf.apache.org/schemas/jaxws.xsd</span>">


<span style="white-space:pre">	</span><import resource="classpath:META-INF/cxf/cxf.xml"/>  
<span style="white-space:pre">	</span><import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>  
<span style="white-space:pre">	</span><import resource="classpath:META-INF/cxf/cxf-servlet.xml"/> 
<span style="white-space:pre">	</span><bean id="hellobServiceImpl" class="test.impl.HelloServiceImpl">
<span style="white-space:pre">	</span></bean>
	
<span style="white-space:pre">	</span><jaxws:server id="helloService" serviceClass="test.OrganizationWebService" address="/helloService">
		<jaxws:serviceBean>
			<ref bean="helloServiceImpl"/>
		</jaxws:serviceBean>    
<span style="white-space:pre">	</span></jaxws:server>


三、编写服务

接口

实现

写完之后 启动tomcat,浏览器地址输入 http://localhost:8080/test/services,即可看到服务。
wsdl地址是  http://localhost:8080/test/services/helloService?wsdl

四、客户端调用

客户端调用有多种方式,请看 官网。本次使用动态调用的方式,具体请看 官网


大功告成!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值