使用Apache CXF和Spring集成创建Web Service

您的评价:
     
还行
 收藏该经验    
 

1.创建HelloWorld 接口类

1 package com.googlecode.garbagecan.cxfstudy.helloworld;
2 import javax.jws.WebParam;
3 import javax.jws.WebResult;
4 import javax.jws.WebService;
5 @WebService
6 public interface HelloWorld {
7     public @WebResult(name="String")String sayHi(@WebParam(name="text") String text);
8 }

2.创建HelloWorld实现类

1 package com.googlecode.garbagecan.cxfstudy.helloworld;
2 public class HelloWorldImpl implements HelloWorld {
3     public String sayHi(String name) {
4         String msg = "Hello " + name + "!";
5         System.out.println("Server: " + msg);
6         return msg;
7     }
8 }

3.修改web.xml文件

01 <!DOCTYPE web-app PUBLIC
02  "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
03  "http://java.sun.com/dtd/web-app_2_3.dtd" >
04 <web-app>
05     <display-name>cxfstudy</display-name>
06     <servlet>
07         <servlet-name>cxf</servlet-name>
08         <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
09         <load-on-startup>1</load-on-startup>
10     </servlet>
11     <servlet-mapping>
12         <servlet-name>cxf</servlet-name>
13         <url-pattern>/ws/*</url-pattern>
14     </servlet-mapping>
15     <listener>
16         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
17     </listener>
18      
19     <context-param>
20         <param-name>contextConfigLocation</param-name>
21         <param-value>classpath*:**/spring.xml</param-value>
22     </context-param>
23      
24 </web-app>

4.创建spring配置文件并放在classpath路径下

01 <?xml version="1.0" encoding="UTF-8"?>
02 <beans xmlns="http://www.springframework.org/schema/beans"
03     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:jaxws="http://cxf.apache.org/jaxws"
04     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd   
05 http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
06     <import resource="classpath:META-INF/cxf/cxf.xml" />
07     <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
08     <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
09     <jaxws:endpoint id="helloworld"implementor="com.googlecode.garbagecan.cxfstudy.helloworld.HelloWorldImpl"address="/HelloWorld" />
10      
11     <!-- For client test -->
12     <jaxws:client id="helloworldClient" address="http://localhost:9000/ws/HelloWorld"serviceClass="com.googlecode.garbagecan.cxfstudy.helloworld.HelloWorld" />  
13 </beans>

5.创建测试类

01 package com.googlecode.garbagecan.cxfstudy.helloworld;
02 import org.springframework.context.ApplicationContext;
03 import org.springframework.context.support.ClassPathXmlApplicationContext;
04 public class SpringClient {
05     public static void main(String[] args) {
06         ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
07         HelloWorld helloworld = (HelloWorld)context.getBean("helloworldClient");
08         System.out.println(helloworld.sayHi("kongxx"));
09     }
10 }

6.测试

6. 1.首先启动tomcat或者使用maven的jetty,并访问http://localhost:9000/ws/HelloWorld?wsdl来验证web service已经启动并且生效;
6. 2.然后运行测试类来验证web service。

使用Apache CXF和Spring集成创建Web Service(zz)的更多相关文章

  1. Apache CXF实战之四 构建RESTful Web Service

    Apache CXF实战之一 Hello World Web Service Apache CXF实战之二 集成Sping与Web容器 Apache CXF实战之三 传输Java对象 这篇文章介绍一下 ...

  2. 使用CXF与Spring集成实现RESTFul WebService

    以下引用与网络中!!!     一种软件架构风格,设计风格而不是标准,只是提供了一组设计原则和约束条件.它主要用于客户端和服务器交互类的软件.基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存 ...

  3. 【spring boot】5.spring boot 创建web项目并使用jsp作前台页面

    贼烦的是,使用spring boot 创建web项目,然后我再idea下创建的,but 仅仅启动spring boot的启动类,就算整个项目都是好着的,就算是能够进入controller中,也不能成功 ...

  4. 基于cxf开发restful风格的Web Service

    一.写在前面 webservice一些简单的其他用法和概念,就不在这里赘述了,相信大家都可以在网上查到,我也是一个新手,写这篇文章的目的一方面是想记录自己成长的历程,另一方面是因为学习这个的时候花了点 ...

  5. 构建一个基于 Spring 的 RESTful Web Service

    本文详细介绍了基于Spring创建一个“hello world” RESTful web service工程的步骤. 目标 构建一个service,接收如下HTTP GET请求: http://loc ...

  6. [翻译]Spring MVC RESTFul Web Service CRUD 例子

    Spring MVC RESTFul Web Service CRUD 例子 本文主要翻译自:http://memorynotfound.com/spring-mvc-restful-web-serv ...

  7. 在Salesforce中创建Web Service供外部系统调用

    在Salesforce中可以创建Web Service供外部系统调用,并且可以以SOAP或者REST方式向外提供调用接口,接下来的内容将详细讲述一下用SOAP的方式创建Web Service并且用As ...

  8. win7 gsoap与vs2010 c++创建Web Service

    ---恢复内容开始--- 之前曾经编写过简单的样例,很久没有碰过,发现已经全部忘记,如今又需要重新巩固一下. 首先是下载gsoap,无法访问官方下载页面,只能在网上搜索,找到一个2.8版本存入云盘以防 ...

  9. 使用Axis2创建Web Service

    Axis2是新一代Web Service开发工具,目前最新版本是1.5.本文主要介绍如何用Axis2创建Web Service. 首先下载二进制包和war包,将war包复制到Tomcat的webapp ...

随机推荐

  1. Appium1.6 GUI界面介绍

    Appium1.6安装详见随笔:http://www.cnblogs.com/meitian/p/7360017.html   下面具体介绍一下GUI界面 1.appium server配置页面 2. ...

  2. jquery获取焦点位于的元素

    参考 https://zhidao.baidu.com/question/497311181016643684.html if ($(":focus").length > 0 ...

  3. Redis数据结构的多种用法

    分布式锁(string) setnx key value,当key不存在时,将 key 的值设为 value ,返回1.若给定的 key 已经存在,则setnx不做任何动作,返回0. 当setnx返回 ...

  4. sourceforge

    sourceforge SourceForge.net,又称SF.net,是开源软件开发者进行开发管理的集中式场所. SourceForge.net由VA Software提供主机,并运行Source ...

  5. java调用微信扫一扫

    步骤: 1,获取Accesstoken(参考我之前的文章) 2,获取jsapiticket(参考我之前的文章) 3,获取签名 4JSSDK使用步骤 步骤一:绑定域名(JS接口安全域名),.否则会报in ...

  6. 8.14 git??sourceTree??

    目前这个项目是四个前端在做,我用的版本控制工具是sourceTree,有两个人用的是命令行,厉害.(刚哥说,肯定要会命令行的,(⊙o⊙)好,我学!!) 上周五提交代码时,文件冲突了,而且我给1.3版本 ...

  7. 音频 PCM 数据的采集和播放

    PCM(Pulse Code Modulation)脉冲编码调制 —— 音频的采集与量化过程. PCM数据是最原始的音频数据完全无损,所以PCM数据虽然音质优秀但体积庞大. 为了解决这个问题先后诞生了 ...

  8. 队列 和 线程 之GCD dispatch

    1.dispatch_queue_create  创建队列开启异步线程(1,4,2,3) // 创建一个队列 dispatch_queue_t queue = dispatch_queue_creat ...

  9. WebAPI支持Session

    1.在App_Start/WebApiConfig.cs中建立建立HttpControllerHandler和HttpControllerRouteHandler 并覆写它: public class ...

  10. SQL Server 通过TSQL(存储过程)用MSXML去调用Webservice

    本文为转载:原文地址 在SQL SERVER 2008 R2 上亲测可用, 这个存储过程配合SoapUI使用效果更好:参考地址 前提设置:http://www.cnblogs.com/chenxizh ...