码迷,mamicode.com
首页 > 编程语言 > 详细

cxf与spring整合

时间:2016-10-15 14:06:06      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

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整合

标签:

原文地址:http://www.cnblogs.com/glblog/p/5963076.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!