1. 程式人生 > >maven+CXF+Spring+tomcat 開發webservice

maven+CXF+Spring+tomcat 開發webservice

<servlet>
		<servlet-name>dispatcher</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:/com/ningpai/web/config/dispatcher-servlet.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<!--CXF配置 2015-02-06 10:12******************************************-->
	<servlet>
		<servlet-name>CXFServlet</servlet-name>
		<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
	</servlet>
	<!--CXF配置 2015-02-06 10:12 ******************************************-->

	<servlet-mapping>
		<servlet-name>dispatcher</servlet-name>
		<url-pattern>*.htm</url-pattern>
	</servlet-mapping>

	<!--CXF配置 2015-02-06 10:12*******************************************-->
		<servlet-mapping>
			<servlet-name>CXFServlet</servlet-name>
			<url-pattern>/ws/*</url-pattern>
		</servlet-mapping>
	<!--CXF配置 2015-02-06 10:12 *******************************************-->

3.在業務模組中編寫spring支援xml將webservice服務類用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:context="http://www.springframework.org/schema/context"
	   xmlns:jaxws="http://cxf.apache.org/jaxws"
	   xmlns:aop="http://www.springframework.org/schema/aop"
	   xmlns:tx="http://www.springframework.org/schema/tx"
	   xmlns:task="http://www.springframework.org/schema/task"
	   xsi:schemaLocation="http://www.springframework.org/schema/beans
		   http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
		   http://www.springframework.org/schema/context
		   http://www.springframework.org/schema/context/spring-context-2.5.xsd
		   http://www.springframework.org/schema/aop
		   http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
		   http://www.springframework.org/schema/tx
		   http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
		   http://www.springframework.org/schema/task
		   http://www.springframework.org/schema/task/spring-task-3.0.xsd
		   http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
	<!-- Memcached配置 <import resource="classpath:simplesm-context.xml" /> <aop:aspectj-autoproxy 
		/> <bean name="defaultMemcachedClient" class="com.google.code.ssm.CacheFactory"> 
		<property name="cacheClientFactory"> <bean name="cacheClientFactory" class="com.google.code.ssm.providers.xmemcached.MemcacheClientFactoryImpl" 
		/> </property> <property name="addressProvider"> <bean class="com.google.code.ssm.config.DefaultAddressProvider"> 
		<property name="address" value="192.168.2.99:11211" /> </bean> </property> 
		<property name="configuration"> <bean class="com.google.code.ssm.providers.CacheConfiguration"> 
		<property name="consistentHashing" value="true" /> </bean> </property> </bean> -->

	<!--CXF配置 2015年02月06日 11:09>>>>>>>>>>>>>>>>>-->
	<import resource="classpath:META-INF/cxf/cxf.xml" />
	<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
	<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
	<!--CXF配置 2015年02月06日 11:09<<<<<<<<<<<<<<<<<<-->

	<!--CXF Service配置 2015年02月06日 11:27-->
	<jaxws:endpoint id="productService" address="/productService" implementorClass="com.kunge.ws.server.IProductService">
		<jaxws:implementor>
			<bean id="productServiceImpl" class="com.<span style="font-family: Arial, Helvetica, sans-serif;">kunge</span><span style="font-family: Arial, Helvetica, sans-serif;">.ws.server.impl.ProductServiceImpl"></span>
				<property name="goodsMapper" ref="GoodsMapper"/>
			</bean>
		</jaxws:implementor>
		<jaxws:features>
			<bean class="org.apache.cxf.feature.LoggingFeature" />
		</jaxws:features>
	</jaxws:endpoint>

</beans>
這裡一定要注意<bean xmlns中對cxf支援的兩處引用,沒有會報錯,即匹配很全面,但未找到jaxws定義之類的錯;