本文就最简单的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. 淘宝的数据库拆分(TDDL)(转)

    淘宝的数据拆分历程 系 统刚开始的时候,因为系统刚上线,用户不多,那个时候,所有的数据都放在了同一个数据库中,这个时候因为用户少压力小,一个数据库完全可以应付的了,但是 随着运营那些哥们辛苦的呐喊和拼 ...

  2. zoj-3782-Ternary Calculation

    题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5269 题目很简单,直接把所有情况列出来. 我的AC代码 #inclu ...

  3. javaweb入门实例---servlet例子

    1.编写servlet: TreeDataServlet.java package com.maggie.tree; import java.io.IOException; import javax. ...

  4. 为应用程序的选项卡及ActionBar设置样式

    示例文件  flex-mobile-dev-tips-tricks-pt2.zip 关于Flex移动开发的提示和技巧有一系列文章,这是其中的第二部分.第一部分集中讲解如何在视图切换及应用程序操作切换之 ...

  5. JSP中使用Taglib

    http://blog.163.com/jany_1016/blog/static/4604400620091112114127341/ http://blog.csdn.net/yuebinghao ...

  6. Codeforces374A

    A. Inna and Pink Pony time limit per test1 second memory limit per test 256 megabytes input standard ...

  7. POJ2479(dp)

    Maximum sum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 39089   Accepted: 12221 Des ...

  8. HDU4496(并查集)

    D-City Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Subm ...

  9. js中的 arguments ,实参的集合

    当 传递的参数个数不确定时,,可使用 arguments ..

  10. 如何利用express新建项目(上)

    如何利用express新建项目(上) 摘要 这篇文章将讲解了如何快速利用express新建项目 一.express4.x的安装 1. npm install -g express 2. npm ins ...