WebService(CXF发布WebService服务与Spring整合)(2)

一、相关基础内容

参见:WebService(CXF对外发布WebService服务)(1)

二、与Spring整合

1、Spring配置文件

在src/main/resources目录下新建webService.xml文件,内容如下(注意:这里引入的cxf.xml等文件是存在于cxf-core.jar中的,只要工程引入了cxf等一系列的jar包,这里就会加载到):

<?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"  
    xmlns:cxf="http://cxf.apache.org/core"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans-2.5.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-extension-soap.xml" />  
    <import resource="classpath*:META-INF/cxf/cxf-servlet.xml" />
	
    <!-- services接口配置 -->    
    <bean id="WebServiceImpl" class="com.cah.ddi3.ws.WebServiceImpl"></bean>

    <!-- CXF 配置WebServices的服务名及访问地址 -->
	<jaxws:server id="WService" address="/WService" serviceClass="com.cah.ddi3.ws.WebServiceI">
		<jaxws:serviceBean>
			<ref bean="WebServiceImpl"/>
		</jaxws:serviceBean>
	</jaxws:server>
	
</beans>

2、web.xml配置

配置加载webService.xml文件

	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:webService.xml</param-value>
	</context-param>

配置cxf servlet

	<servlet>  
        <servlet-name>CXFServlet</servlet-name> 
        <display-name>CXFServlet</display-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>/ws/*</url-pattern> 
	</servlet-mapping>

三、验证

至此,已经整合完成,启动服务,访问:http://localhost:8080/<工程名>/ws,呈现如下页面,表明发布成功:




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值