首页 > 代码库 > cxf与spring整合

cxf与spring整合

1.创建web项目

2.创建接口

  

3.创建实现类

  

4.配置spring配置文件applicationContext.xml

  4.1spring的头配置:

<?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:jaxws="http://cxf.apache.org/jaxws"    xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core"    xsi:schemaLocation="http://www.springframework.org/schema/beans                             http://www.springframework.org/schema/beans/spring-beans.xsd                            http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd                            http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd                            http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd"></beans>

 4.2具体配置(类的初始化)

<!-- 对jaxWSServerFactoryBean的封装--><jaxws:server address="/weather" serviceClass="cn.skywin.cxf.server.WeatherInterface">    <jaxws:serviceBean>        <ref bean="weatherInterface"/>       </jaxws:serviceBean>    <bean name="weatherInterface" class="cn.skywin.cxf.server.WeatherInterfaceImpl"></bean></jaxws:server>

5.配置web.xml 

  5.1web 项目为servlet容器,所有的类要在里面进行声明。

  5.2加载spring配置文件

  <!--设置spring环境-->  <context-param>      <!--contextConfigLocation是不能修改的  -->      <param-name>contextConfigLocation</param-name>      <param-value>classpath:applicationContext.xml</param-value>  </context-param>  <!--加载配置文件-->  <listener>     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  </listener>

   5.3配置servlet

  <servlet>      <servlet-name>CXF</servlet-name>      <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>  </servlet>  <!--映射(路径和扩展映射)--->  <servlet-mapping>      <servlet-name>CXF</servlet-name>      <url-pattern>/ws/*</url-pattern>  </servlet-mapping>

 

cxf与spring整合