1.创建HelloWorld 接口类

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

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. return msg;
  6. }
  7. }

3.修改web.xml文件

  1. <!DOCTYPE web-app PUBLIC
  2. "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  3. "http://java.sun.com/dtd/web-app_2_3.dtd" >
  4. <web-app>
  5. <display-name>cxfstudy</display-name>
  6. <servlet>
  7. <servlet-name>cxf</servlet-name>
  8. <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
  9. <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. <context-param>
  19. <param-name>contextConfigLocation</param-name>
  20. <param-value>classpath*:**/spring.xml</param-value>
  21. </context-param>
  22. </web-app>

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

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  5. http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
  6. <import resource="classpath:META-INF/cxf/cxf.xml" />
  7. <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
  8. <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
  9. <jaxws:endpoint id="helloworld" implementor="com.googlecode.garbagecan.cxfstudy.helloworld.HelloWorldImpl" address="/HelloWorld" />
  10. <!-- For client test -->
  11. <jaxws:client id="helloworldClient" address="http://localhost:9000/ws/HelloWorld" serviceClass="com.googlecode.garbagecan.cxfstudy.helloworld.HelloWorld" />
  12. </beans>

5.创建测试类

  1. package com.googlecode.garbagecan.cxfstudy.helloworld;
  2. import org.springframework.context.ApplicationContext;
  3. import org.springframework.context.support.ClassPathXmlApplicationContext;
  4. public class SpringClient {
  5. public static void main(String[] args) {
  6. ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
  7. HelloWorld helloworld = (HelloWorld)context.getBean("helloworldClient");
  8. System.out.println(helloworld.sayHi("kongxx"));
  9. }
  10. }

6.测试

6.1 首先启动tomcat或者使用maven的jetty,并访问http://localhost:9000/ws/HelloWorld?wsdl来验证web service已经启动并且生效;

6.2 然后运行测试类来验证web service。

CXF整合Sping与Web容器的更多相关文章

  1. Apache CXF实战之二 集成Sping与Web容器

    本文链接:http://blog.csdn.net/kongxx/article/details/7525481 Apache CXF实战之一 Hello World Web Service 书接上文 ...

  2. Geronimo tomcat: 在 Apache Geronimo 插件体系中将 Apache Tomcat 这个优秀的 Web 容器整合至其中

    Apache Geronimo 灵活的插件体系将 Tomcat, OpenJPA, OpenEJB, ActiveMQ 等第三方组件集成至其中.本文从多角度介绍了在 Apache Geronimo 中 ...

  3. Spring学习(十九)----- Spring与WEB容器整合

    首先可以肯定的是,加载顺序与它们在 web.xml 文件中的先后顺序无关.即不会因为 filter 写在 listener 的前面而会先加载 filter.最终得出的结论是:listener -> ...

  4. 【Java EE 学习 81】【CXF框架】【CXF整合Spring】

    一.CXF简介 CXF是Apache公司下的项目,CXF=Celtix+Xfire:它支持soap1.1.soap1.2,而且能够和spring进行快速无缝整合. 另外jax-ws是Sun公司发布的一 ...

  5. WebService学习之三:spring+cxf整合

    步骤一:spring项目(java web项目)引入CXF jar包 步骤二:创建webservice服务器 1)创建一个服务接口 package com.buss.app.login; import ...

  6. 【WebService】——CXF整合Spring

    相关博客: [WebService]--入门实例 [WebService]--SOAP.WSDL和UDDI 前言: 之前的几篇博客基本上都是使用jdk来实现WebService的调用,没有使用任何框架 ...

  7. day63-webservice 11.cxf整合spring

    如果我们有Spring配置文件,怎么把WebService整合到Spring里面,用Ioc容器来管理这个Bean. 做项目的时候一般都是分层:Dao层.Service层.Service层要调Dao层, ...

  8. spring与cxf整合配置webservice接口(以jaxws:server的方式配置)

    ps:最近项目需要跟其他系统做同步,需要使用webservice来提供接口给其他系统调用:临时抱佛脚赶紧去网上找了下资料,发现用Endpoint的方式发布接口好容易哦:赶紧写了个例子做验证,发布成功. ...

  9. webservice 服务端例子+客户端例子+CXF整合spring服务端测试+生成wsdl文件 +cxf客户端代码自动生成

    首先到CXF官网及spring官网下载相关jar架包,这个不多说.webservice是干嘛用的也不多说. 入门例子 模拟新增一个用户,并返回新增结果,成功还是失败. 大概的目录如上,很简单. Res ...

随机推荐

  1. FileUpload1.PostedFile.FileName 获取的文件名

    例如文件叫做 c:\web\a.jpg 如果用IE,则返回   c:\web\a.jpg 含路径 如果用Chrome,则返回 a.jpg 不含路径.

  2. C# System.Threading.AutoResetEvent

    表示线程同步事件在一个等待线程释放后收到信号时自动重置. using System; using System.Threading; // Visual Studio: Replace the def ...

  3. Python随机字符串验证码

    def code_get(self): source = ['] #数字验证码 # source = [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H','I','J', ...

  4. Windows下python3生成UTF8的CSV文件和sha256sum踩坑记录

    CSV的坑 在Ubuntu下是简单的写入完事 import csv ... with open(filename, 'w') as output: f = csv.writer(output) f.w ...

  5. 试水STF(smartphone test farm)

    STF简介 简介: STF , smartphone test farm, 是一款能够通过浏览器远程管理智能设备的系统, 能为移动自动化测试提供方便快捷的服务,免去测试工程师的后顾之忧. 功能点: 支 ...

  6. 唯一ID算法之:snowflake(Java版本)

    Twitter开源的算法,简单易用. /** * Twitter_Snowflake<br> * SnowFlake的结构如下(每部分用-分开):<br> * 0 - 0000 ...

  7. window.print控制打印样式

    我们可能会去使用window.print()方法来打印页面,但是当我们遇到需要改变打印时候的字体大小等css样式的时候你可能会懵逼. 所以搜索成了我们的必经之路,我相信在网上搜索出来的最好的答案就是使 ...

  8. python3 + flask + sqlalchemy +orm(1):链接mysql 数据库

    1.pycharm中新建一个flask项目 2.按装flask.PyMySQL.flask-sqlalchemy 3.项目下面新建一个config.py 文件 DEBUG = True #dialec ...

  9. shell 实例

    转载自:https://github.com/liquanzhou/ops_doc    这里只作为笔记使用,不做他用 shell实例手册 0 说明{ 手册制作: 雪松 更新日期: 2018-09-1 ...

  10. vim资源

    1.http://vimcasts.org vim技巧,还有一个高达120美元的课程 目前,正在看http://vimcasts.org/blog/2013/02/habit-breaking-hab ...