java的WebService实践(cxf)

Java发布WebService,结合Spring,通过cxf的方式

难点:1、引用什么jar包;

  

1、创建接口

源码如下:

package com.nankang;import javax.jws.WebParam;
import javax.jws.WebService;@WebService
public interface HelloWorld {String sayHi(@WebParam(name="text") String text);
}

2、实现接口

源码如下:

package com.nankang;import javax.jws.WebService;@WebService(endpointInterface="com.nankang.HelloWorld",serviceName="HelloWorld")
public class HelloWorldImpl implements HelloWorld {public String sayHi(String text) {// TODO Auto-generated method stubreturn "Hello" + text;}}

3、web.xml的配置

源码如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><servlet><servlet-name>CXFServlet</servlet-name><servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>CXFServlet</servlet-name><url-pattern>/webservice/*</url-pattern></servlet-mapping>
</web-app>

4、添加applicationContext.xml

源码如下:

<?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:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jaxws="http://cxf.apache.org/jaxws"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsdhttp://cxf.apache.org/jaxwshttp://cxf.apache.org/schemas/jaxws.xsd"><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" /><!-- 扫描spring注解配置 --><context:component-scan base-package="com.nankang.contactqueryservice" /><jaxws:endpoint id="helloWorld" implementor="com.nankang.HelloWorldImpl"address="/helloWorld" /></beans>

5、访问

http://localhost:8080/WebServiceTest/webservice/helloWorld?wsdl

6、访问源码

package com.nankang;import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class HelloWorldClient {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubJaxWsProxyFactoryBean svr = new JaxWsProxyFactoryBean();svr.setServiceClass(HelloWorld.class);svr.setAddress("http://localhost:8080/WebServiceTest/webservice/helloWorld");HelloWorld hw = (HelloWorld)svr.create();System.out.println(hw.sayHi("ddddaaaa"));}
}

7、发布示例:

package com.nankang;import javax.xml.ws.Endpoint;public class WebServiceApp {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubSystem.out.println("web service start");HelloWorldImpl implementor = new HelloWorldImpl();String address = "http://localhost:8080/helloWorld";Endpoint.publish(address, implementor);System.out.println("web service started");}}

参考:

http://blog.sina.com.cn/s/blog_a0e7e34c0101959p.html

http://www.cnblogs.com/frankliiu-java/articles/1641949.html

posted on 2014-07-20 01:00 daixinet.com 阅读(...) 评论(...) 编辑 收藏

转载于:https://www.cnblogs.com/sshoub/p/3855719.html

java的WebService实践(cxf)相关推荐

  1. Apache CXF生成java代码用java调用Webservice接口

    这里写自定义目录标题 使用java调用webservice接口 使用java调用webservice接口 当我们使用java去访问webservice的接口时,有很多种方式,这里我们使用apache ...

  2. WebService它CXF注释错误(两)

    WebService它CXF注解 1.详细报错例如以下 五月 04, 2014 11:24:12 下午 org.apache.cxf.wsdl.service.factory.ReflectionSe ...

  3. java 微服务实践 视频,全新JAVA微服为务实战Spring Boot系列视频教程 小马哥 JAVA微服务实践视频课程...

    全新JAVA微服为务实战Spring Boot系列视频教程 小马哥 JAVA微服务实践视频课程 ===============课程目录=============== ├─(1) 03Java 微服务实 ...

  4. 转载 WebService 的CXF框架 WS方式Spring开发

    WebService 的CXF框架 WS方式Spring开发 1.建项目,导包. 1 <project xmlns="http://maven.apache.org/POM/4.0.0 ...

  5. java小马哥百度网盘_思否编程(小马哥):Java 微服务实践 - Spring Boot / Spring Cloud全套,完整版下载 - VIPC6资源网...

    小马哥 Java 微服务实践 – Spring Boot 系列 pptx segmentfault-lessons-master 03Java 微服务实践 – Spring Boot 系列(三)Web ...

  6. java调用接口速度慢,Java 调用 webservice 接口,为什么这么慢

    Java 调用 webservice 接口,为什么这么慢,有没有好的优化方案,本人目前改成 http 方式发 soap 消息调用,速度依旧很慢,维持在平均 100ms 下不来. 之前用 cxf 的 J ...

  7. java调用WebService(客户端)

    java调用WebService(客户端) 看下了网上大部分都是写java来编写WS服务端,写了下JAVA的调用端. WebService可以有Get. Post.Soap.Document四种方式调 ...

  8. java小马哥mercyblitz,小马哥 Java 微服务实践 - Spring Boot 系列

    资源介绍 教程名称:小马哥 Java 微服务实践 - Spring Boot 系列 教程目录: 03Java 微服务实践 - Spring Boot 系列(三)Web篇(中) 04Java 微服务实践 ...

  9. .NET调用JAVA的WebService方法

    调用WebService,最简单的办法当然是直接添加WEB引用,然后自动产生代理类,但是在调用JAVA的WebService时并没有这么简单,特别是对于SoapHeader的处理,在网上也有相关资料, ...

最新文章

  1. python的try和except_python的try...except
  2. buu [GXYCTF2019]CheckIn
  3. Ping Function
  4. CentOS系统启动流程和系统初始化
  5. oracle中做数据字典,oracle中数据字典是干嘛用的啊
  6. python类库31[文件和目录os+os.path+shutil]
  7. 【Leetcode | 12】342. 4的幂
  8. 给linux添加新硬盘
  9. 打开Android Studio报错required plugin “Android Support” is disabled
  10. vue怎么实现右键二级菜单_vue中如何自定义右键菜单详解
  11. java doc书写_apidoc利用代码注释书写文档
  12. WordPress淘宝客ZZDGM主题Upanel插件使用补充
  13. windows下批量更改文件后缀
  14. 利用公网Msf+MS17010跨网段攻击内网(不详细立马关站)
  15. CTEX 各种命令、符号
  16. 9 款最好的免费博客网站对比
  17. Unsupervised Domain Adaptation by Backpropagation
  18. APPInventor网络数据库浏览器(TinyWebDB查询API)
  19. 成像系统光照度(相机成像辐射传输)
  20. 我的理想计算机系100字,我的理想作文100字

热门文章

  1. 童年记忆-莴苣姑娘的故事
  2. C# 正则表达式小结
  3. Python函数01/函数的初识/函数的定义/函数调用/函数的返回值/函数的参数
  4. Matplotlib pyplot中title() xlabel() ylabel()无法显示中文(即显示方框乱码)的解决办法...
  5. 设计模式(七):桥接模式
  6. 关于requestAnimationFrame与setInterval的一点差异
  7. 【bzoj3224】 Tyvj1728—普通平衡树
  8. kettle中通过 时间戳(timestamp)方式 来实现数据库的增量同步操作(一)
  9. javascript判断浏览器核心
  10. SD--如何配置发票分割开票