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

Spring+CXF的WebServices简单示例的更多相关文章

  1. spring boot 结合jsp简单示例

    引入依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>sp ...

  2. Spring Boot + Docker + K8S 简单示例

    前言 最近看了看k8s,感觉用这个管理docker确实比自己写一坨脚本进步太多了,简直不是一个次原的东西. 看着k8s的官方文档随手写了个小Demo,一个基于k8s的spring boot服务. 代码 ...

  3. Spring MVC Theme(简单示例)

    在渲染视图的spring-web中,配置them. 实现两个接口就可以使用: ResourceBundleThemeSource  --> 用于确定要使用的主题的名字(theme name) S ...

  4. Spring MVC 文件上传简单示例(form、ajax方式 )

    1.Form Upload SpringMVC 中,文件的上传是通过 MultipartResolver 实现的,所以要实现上传,只要注册相应的 MultipartResolver 即可. Multi ...

  5. WebService之Spring+CXF整合示例

    一.Spring+CXF整合示例 WebService是一种跨编程语言.跨操作系统平台的远程调用技术,它是指一个应用程序向外界暴露一个能通过Web调用的API接口,我们把调用这个WebService的 ...

  6. 使用CXF开发WebService程序的总结(七):Spring+CXF+Mybatis+Mysql共同打造的服务端示例

    通过该demo,可以 熟悉下 spring+cxf+maven+mybatis+mysql等常见后端技术整合 1. 在前面的 父工程 ws_parent 中 添加依赖 由于原来的项目是使用的cxf依赖 ...

  7. 【Spring-AOP-学习笔记-7】@Around增强处理简单示例

    阅读目录 简单介绍 章节1:项目结构 章节2:定义切面类.连接点注解类 章节3:为待增强的方法--添加注解声明 章节4:AspectJ配置文件 章节5:测试类xxx 章节6:测试结果 Around 增 ...

  8. [xfire]使用xfire开发webservice的简单示例

    目前项目上有用到xfire,所以临时看了些xfire的资料和示例,自己照着写了一个简单示例. xfire在2007年后已经停止更新,正式更名为apache cxf,也可以说是xfire2.0. xfi ...

  9. Spring IO Platform简介及示例

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

随机推荐

  1. HBuilder开发App教程04-最难搞定的是mui

    前言 前几篇说到一些HBuilder开发app的基础教程, 现在来说一下HBuilder开发app的难点,或者说是上手的难点, 就是mui, 如果你没有研究mui就贸然的上手HBuilder,那你的开 ...

  2. Memo 的当前行、当前列与当前字符

    procedure TForm1.Memo1Click(Sender: TObject); begin   Text := Format('当前列:%d, 当前行:%d', [Memo1.CaretP ...

  3. --@angularJS--$http服务与后台数据交互

    1.httpBasic.html: <!DOCTYPE HTML><html ng-app="app"><head>    <title& ...

  4. iOS NSTimer

    示例: //创建 scrollTimer =[NSTimer scheduledTimerWithTimeInterval:interval target:self selector:@selecto ...

  5. HDU-1395-2^x mod n = 1(数学题(二次出错))

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1395 这题一定要滴水不漏的把所有代码全部看完. 这个题目是一个数学类型的题,我也没思路,只知道n== ...

  6. jQuery事件绑定、解绑、命名空间

    jQuery事件绑定.解绑.命名空间 <%@ page language="java" import="java.util.*" pageEncoding ...

  7. js数组快速排序

    <script type="text/javascript"> var arr = [1, 2, 3, 54, 22, 1, 2, 3]; function quick ...

  8. zoj3823--构造

    题目大意: 在n*n(n<=512)的网格上,从边界某个点出发,经过每个点一次且回到边界上,构造出一种方案使拐弯的数量至少为n*(n-1)-1次. 构造方法:我们可以手算出n=2~6时的方案. ...

  9. 新年上班第一天,我的 IDE 挂了

    新的一年又开始了 你年前的总结还记得么?你新年的计划做好了么?反正我都没做. 上班第一天大家都在晒着开工红包,看着一个比一个刷到的红包多,庆幸自己幸好没结婚:开心的聊着过年又被七大姑八大姨爷爷奶奶爸爸 ...

  10. secureCRT端口转发功能

    总共有三台机器: A是办公网络的windows主机, B是一台linux堡垒机(114.144.xxx.xx), C是内网生产环境一台linux机器(192.168.1.6), A只能访问B但A不能访 ...