[Cxf] spring-cxf 配置

1.在web.xml中配置servlet

<!-- spring监听的配置 -->
<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- servlet的配置 --> <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>/*</url-pattern> </servlet-mapping> ============================================================== <!-- CXF --> <servlet>   <servlet-name>CXFService</servlet-name>   <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> </servlet> <!-- CXF mapping--> <servlet-mapping>   <servlet-name>CXFService</servlet-name>   <url-pattern>/kjt/webservice/*</url-pattern> </servlet-mapping> =============================================================== 2 在applicationContext.xml里面配置cxf的xml <!-- webservice --> <import resource="classpath:/config/applicationContext-cxf-service.xml" /> =============================================================== 3 cxf配置文件--applicationContext-cxf-service.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:cxf="http://cxf.apache.org/core" xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> <import resource="classpath:META-INF/cxf/cxf.xml"/> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <!-- provider 定义 --> <bean id="jaxbProvider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider" /> <bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" p:mapper-ref="jacksonMapper"/> <bean id="jacksonMapper" class="org.codehaus.jackson.map.ObjectMapper"> <property name="serializationConfig.dateFormat"> <bean class="java.text.SimpleDateFormat"> <constructor-arg value="yyyy-MM-dd HH:mm:ss"/> </bean> </property> <property name="serializationConfig.serializationInclusion" value="NON_NULL"></property> </bean>   <!-- 用于从json串中获取的字符串,转化成Date类型 --> <bean id="dateHandler" class="com.goldenvista.scaffold.utils.date.DateParameterHandler"> <property name="format" value="yyyy-MM-dd"></property> </bean>   
  
  <!--
用于从json串中获取的字符串,转化成Date类型 --> <bean id="dateTimeHandler" class="com.goldenvista.scaffold.utils.date.DateParameterHandler"> <property name="format" value="yyyy-MM-dd HH:mm:ss"></property> </bean> <!-- 服务定义 ,用于模块化发布REST服务,供客户端调用--> <jaxrs:server id="ecsCarService" address="/" > <jaxrs:serviceBeans> <ref bean="kjtService" /> <ref bean="kjtMilkTraceService" /> <ref bean="userCenterService"/> <ref bean="saleService"/> </jaxrs:serviceBeans> <jaxrs:extensionMappings> <entry key="json" value="application/json"/> <entry key="xml" value="application/xml"/> </jaxrs:extensionMappings> <jaxrs:providers> <ref bean="jsonProvider"/> <ref bean="jaxbProvider"/> <ref bean="dateHandler" /> </jaxrs:providers> </jaxrs:server> </beans>

 

posted @ 2014-06-10 13:49  Aviva_ye  阅读(1335)  评论(0编辑  收藏  举报