本文就最简单的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. Delphi拷贝目录(含子目录)的方法

    要实现目录级的拷贝,可以利用Windows API函数ShFileOperation( ),其函数声明如下: WINSHELLAPI int WINAPI SHFileOperation( LPSHF ...

  2. HDU 3374 String Problem (KMP+最大最小表示)

    HDU 3374 String Problem (KMP+最大最小表示) String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  3. Java线程:线程交互

    一.基础知识 java.lang.Object的类的三个方法: void notify():唤醒在此对象监视器上等待的单个线程. void notifyAll():唤醒在此对象监视器上等待的所有线程. ...

  4. spring mvc 入门示例

    classpath <?xml version="1.0" encoding="UTF-8"?> <classpath> <cla ...

  5. JS加载相对路径脚本的方法 - 汇总

    js加载脚本的方式有很多,但是各有各的用途. 最近公司https项目改造,对于资源文件这一块,也是遇到一些问题,现在就来总结一下,怎样改造https的脚本吧~! 方法1.借助服务端语言如PHP,输入当 ...

  6. ASP.NET Zero--15.一个例子(8)商品分类管理-权限控制

    1.添加权限常量 打开文件AppPermissions.cs [..\MyCompanyName.AbpZeroTemplate.Core\Authorization\AppPermissions.c ...

  7. QEMU ELF_LOAER分析[基于MIPS]

    本文用于记录对QEMU对ELF文件加载函数进行分析.根据“函数使用->函数定义->函数实现->函数实现的分析”的顺序进行分析,最终提取出ELF文件加载的代码. 1. load_elf ...

  8. 【转】OSX键盘快捷键

    OS X 键盘快捷键 了解有关常见 OS X 键盘快捷键的信息.键盘快捷键是通过按下键盘上的组合键来调用 OS X 功能的一种方式. 若要使用键盘快捷键或按键组合,您可以同时按修饰键和字符键.例如,同 ...

  9. SuperSocket入门(五)-常用协议实现模版及FixedSizeReceiveFilter示例

             Socket里面的协议解析是Socket通讯程序设计中最复杂的地方,如果你的应用层协议设计或实现不佳,Socket通讯中常见的粘包,分包就难以避免.SuperSocket内置了命令行 ...

  10. Java错题

    加粗为正确答案,绿色为错选答案 1.对于以下代码: for ( int i=0; i<10; i++)  System.out.println(i); for循环后,i的值是多少? A.i不再存 ...