CXF与Web项目集成---with Spring

1.CXF本身就使用了Spring的东西,它和Spring集成可谓是无缝集成

   主要让发布服务的任务交spring去发布

 

2.配置web.xml

  配置spring

 

Xml代码    收藏代码
  1. <context-param>  
  2.         <param-name>contextConfigLocation</param-name>  
  3.         <param-value>WEB-INF/beans.xml</param-value>  
  4.     </context-param>  
  5.   
  6.     <listener>  
  7.         <listener-class>  
  8.             org.springframework.web.context.ContextLoaderListener  
  9.         </listener-class>  
  10.     </listener>  

 

 

  配置我们的cxf

 

Xml代码    收藏代码
  1. <!-- 配置CXF Servlet -->  
  2.     <servlet>  
  3.         <servlet-name>CXFServlet</servlet-name>  
  4.         <servlet-class>  
  5.             org.apache.cxf.transport.servlet.CXFServlet  
  6.         </servlet-class>  
  7.         <load-on-startup>1</load-on-startup>  
  8.     </servlet>  
  9.   
  10.     <servlet-mapping>  
  11.         <servlet-name>CXFServlet</servlet-name>  
  12.         <url-pattern>/*</url-pattern>  
  13.     </servlet-mapping>  

 

3.beans.xml

 

Xml代码    收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!-- START SNIPPET: beans -->  
  3. <beans xmlns="http://www.springframework.org/schema/beans"  
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  5.     xmlns:jaxws="http://cxf.apache.org/jaxws"  
  6.     xsi:schemaLocation="  
  7. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
  8. http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">  
  9.   
  10.    
  11.     <!--会向cxf jar包去找  -->  
  12.     <import resource="classpath:META-INF/cxf/cxf.xml" />  
  13.     <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />  
  14.     <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />  
  15.   
  16.     <!--   
  17.     <jaxws:endpoint   
  18.       id="helloWorld"   
  19.       implementor="com.cxf.server.HelloWorldImpl"   
  20.       address="/HelloWorld" />  
  21.     -->  
  22.         
  23.       <!-- 另一种发布方式 -->  
  24.       <bean id="hello" class="com.cxf.server.HelloWorldImpl"/>  
  25.       <jaxws:endpoint id="helloWorld"   
  26.                       implementor="#hello"  
  27.                       address="/HelloWorld">  
  28.                         
  29.       </jaxws:endpoint>  
  30.           
  31.       <bean id="us" class="com.cxf.users.UserServiceImpl"></bean>  
  32.         
  33.       <jaxws:endpoint id="userService"  
  34.                       implementor="#us"  
  35.                       address="/userAction"  
  36.                       >  
  37.             <jaxws:inInterceptors>  
  38.                 <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>  
  39.             </jaxws:inInterceptors>  
  40.                       
  41.             <jaxws:outInterceptors>  
  42.                 <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean>  
  43.             </jaxws:outInterceptors>  
  44.       </jaxws:endpoint>  
  45.         
  46. </beans>  
  47. <!-- END SNIPPET: beans -->  

 

 <jaxws:endpoint  通过他们进行服务发布,通过其指定的address访问你的wsdl

 

Xml代码    收藏代码
  1. <jaxws:inInterceptors>  
  2.                 <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>  
  3.             </jaxws:inInterceptors>  

 可以加入相关interceptor

你可能感兴趣的:(CXF与Web项目集成---with Spring)