本文就最简单的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.xsdhttp://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. 运行

转载于:https://www.cnblogs.com/zhaiqianfeng/p/4622605.html

Spring+CXF的WebServices简单示例相关推荐

  1. Spring JdbcTemplate + transactionTemplate 简单示例 (零配置)

    jdbcTemplate简介 Spring对数据库的操作在jdbc上面做了深层次的封装,使用spring的注入功能,可以把DataSource注册到JdbcTemplate之中. JdbcTempla ...

  2. Spring IO Platform简介及示例

    什么是Spring IO Platform Spring IO Platform,简单的可以认为是一个依赖维护平台,该平台将相关依赖汇聚到一起,针对每个依赖,都提供了一个版本号: 这些版本对应的依赖都 ...

  3. Spring MVC文件上传示例教程 - 单个和多个文件

    Spring MVC文件上传示例教程 - 单个和多个文件 文件上传是任何Web应用程序中非常常见的任务.我们之前已经看过如何在Servlet和Struts2文件上传中上传文件.今天我们将学习Sprin ...

  4. Spring Security MVC登录注销示例教程

    Spring Security MVC登录注销示例教程 今天我们将了解Spring Security Login Example.在阅读这篇文章之前,请先阅读我在"Spring 4 Secu ...

  5. java中的mapper是什么_Java使用ObjectMapper的简单示例

    一.什么是ObjectMapper? ObjectMapper类是Jackson库的主要类,它提供一些功能将数据集或对象转换的实现. 它将使用JsonParser和JsonGenerator实例来实现 ...

  6. Activemq Jms 简单示例

    Activemq Jms 简单示例 简介     简单的 Activemp JMS 示例代码 activemq 运行     简单使用docker启动一个: docker run -dit --nam ...

  7. ShardingSphere-Proxy 分库分表 简单示例

    ShardingSphere-Proxy 分库分表 简单示例 简要说明     对一张简单的订单表数据表进行水平分库分表,拆分2个库,每个库16张表并在新结构在演示常见的增删改查操作 环境配置 设置M ...

  8. Flowable 6.6.0 BPMN用户指南 -10 流程实例迁移 - 10.1 简单示例

    Flowable 6.6.0 用户指南相关文档下载 BPMN用户指南 第一部分 - 中文PDF精编版 BPMN用户指南 第二部分 - 中文PDF精编版 BPMN用户指南 第三部分 - 中文PDF精编版 ...

  9. 通用 Mapper UUID 简单示例

    通用 Mapper UUID 简单示例 不可回写的 UUID 通用 Mapper 中对 UUID 的用法主要提到了一种专有的写法,如下写法: @GeneratedValue(generator = & ...

最新文章

  1. 第4关:16位快速加法器设计
  2. 买了一个软件测试就业班课程,不知道值不值
  3. [BZOJ 2588]Count on a tree
  4. java处理高并发高负载类网站的优化方法
  5. atxserver运行没有反应_连续生物工艺:灌流生物反应器
  6. PHP服务端推送技术Long Polling
  7. 想悄悄的做渗透测试?这里的工具足够你用了
  8. sql server 查询当前月份日期列表数据
  9. c语言实训项目,C语言项目实训教程
  10. 如何看懂蓝桥杯单片机(CT107S)原理图
  11. 截止失真放大电路_音频功放失真?别急!这里有常见改善方法
  12. 串口协议和RS-232标准,RS232电平与TTL电平的区别,以及USB/TTL转232“模块(CH340芯片为例)的工作原理
  13. Android Kiosk 模式
  14. 用java编写进制转换器_JAVA 简单进制转换器
  15. Excel表格误删怎么恢复
  16. excel 设置表头表尾
  17. 嵌入式计算机系统简述,嵌入式系统定义_简述嵌入式系统的定义和组成
  18. 用python实现身份证号校验系统
  19. 多段曲线控温“核函数“算法分析(完整梯形图源代码)
  20. Qt 编译错误:C2228: “.key”的左边必须有类/结构/联合

热门文章

  1. 非正常关机导致无法启动MYSQL提示丢失mysql.sock的解决办法
  2. C项目案例实践(0)-语言基础
  3. ApiBoot - ApiBoot Swagger 使用文档
  4. OAuth2:隐式授权(Implicit Grant)类型的开放授权
  5. Dropping Balls(小球下落)
  6. Spring的事务管理难点剖析(1):DAO和事务管理的牵绊
  7. amd显卡风扇调节_为什么NVIDIA和AMD公版显卡纷纷摒弃涡轮散热器而采用多风扇散热设计?...
  8. socket bufferedinputstream通信读取不到服务器返回的响应_TCP角度看socket通信过程,socket怎么表示三次握手,四次挥手...
  9. pc工具不支持stb的加密方式_那些工作中常用的实用工具
  10. java调用python脚本_调用Python写vb的脚本方法