本文就最简单的WebServices示例来演示Spring和CXF的整合。

  1. 使用Maven创建webapp项目,pom如下

    <properties>
    <cxf.version>2.2.3</cxf.version>
    </properties> <dependencies>
    <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    </dependency> <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>4.1.4.RELEASE</version>
    </dependency> <dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-frontend-jaxws</artifactId>
    <version>${cxf.version}</version>
    </dependency>
    <dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-transports-http</artifactId>
    <version>${cxf.version}</version>
    </dependency>
    <!-- Jetty is needed if you're are not using the CXFServlet -->
    <dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-transports-http-jetty</artifactId>
    <version>${cxf.version}</version>
    </dependency> <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
    </dependency>
    </dependencies>
  2. 需要暴露的服务
    @WebService
    public class Hello {
    public String say(){
    return "hello,kevin";
    }
    }
  3. 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:jaxws="http://cxf.apache.org/jaxws"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <bean id="hello" class="net.oseye.Hello"></bean> <import resource="classpath:META-INF/cxf/cxf.xml" />
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <jaxws:endpoint id="helloService" implementor="#hello" address="/hello" />
    </beans>
  4. web.xml
    <!DOCTYPE web-app PUBLIC
    "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app>
    <display-name>Archetype Created Web Application</display-name> <!-- needed for ContextLoaderListener -->
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
    </context-param> <!-- Bootstraps the root web application context before servlet initialization -->
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener> <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>/*</url-pattern>
    </servlet-mapping>
    </web-app>
  5. 运行

最新文章

  1. Win8 安装 Scrapy
  2. 查询Oracle锁表和解决方法
  3. elk收集分析nginx access日志
  4. HTML解析组件HtmlAgilityPack使用
  5. Solr 5.x集成中文分词word,mmseg4j
  6. OpenGL中投影矩阵的推导
  7. 加入商品分类信息,考虑用户所处阶段的 图模型 推荐算法 Rws(random walk with stage)
  8. 非原生APP开发中可以用到的JQ插件
  9. Lake Counting (DFS)
  10. 2017-12-30-如何彻底清除现存GIT仓库的大量提交历史
  11. NTP 时间同步协议
  12. 【Tomcat】CentOS7.0下安装多个Tomcat及其配置
  13. css美化页面
  14. ubuntu 禁用自带的nouveau显卡驱动,安装NVIDIA显卡驱动
  15. mono修改配置
  16. topcoder srm 684 div1
  17. Markdown基础教程
  18. linux-shell脚本高并发对文本url批量下载
  19. (2)集合 遍历set集合
  20. 20155231 2016-2017-2 《Java程序设计》第1周学习总结

热门文章

  1. package.json 里 devDependencies和dependencies的区别
  2. 选项卡(TabHost)的功能与用法
  3. Spring mvc配置Json返回
  4. 你不知道的getComputedStyle
  5. C#中let字句
  6. 蓝桥网试题 java 基础练习 回文数
  7. ajax入门之建立XHR对象 (1)
  8. BOM数据基础 - Mobox物料编码管理及实现
  9. 一次开放接口从需求分析到发布sdk线上包
  10. 使用express.js框架一步步实现基本应用以及构建可扩展的web应用