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 stub
return "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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://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.xsd
http://cxf.apache.org/jaxws
http://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 stub
JaxWsProxyFactoryBean 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 stub
System.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
java的WebService实践(cxf)的更多相关文章
- 转-JAVA webservice之CXF 范例--http://cxshun.iteye.com/blog/1275408
JAVA webservice之CXF 博客分类: j2ee相关 昨天我们一起学习了一下xfire,今天我们来看一下CXF,为什么学完那个接着学这个呢.因为CXF是在xfire的基础上实现 的,所以我 ...
- Java调用WebService方法总结(7)--CXF调用WebService
CXF = Celtix + XFire,继承了Celtix和XFire两大开源项目的精华,是一个开源的,全功能的,容易使用的WebService框架.文中所使用到的软件版本:Java 1.8.0_1 ...
- java 调用webservice的各种方法总结
java 调用webservice的各种方法总结 几种流行的开源WebService框架Axis1,Axis2,Xfire,CXF,JWS比较 方法一:创建基于JAX-WS的webservice(包括 ...
- Java之webService知识
Java之webService知识 1 webservice基础知识 1.1 webService请求的本质 一次webService本质请求,如下所示: 1.2 wsdl文档解析 wsdl文档元素结 ...
- WebService之CXF注解报错(一)
WebService之CXF注解 1.详细报错例如以下 usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] ...
- WebService它CXF注释错误(两)
WebService它CXF注解 1.详细报错例如以下 五月 04, 2014 11:24:12 下午 org.apache.cxf.wsdl.service.factory.ReflectionSe ...
- WebService之CXF注解报错(三)
WebService之CXF注解 1.具体错误如下 五月 04, 2014 11:29:28 下午 org.apache.cxf.wsdl.service.factory.ReflectionServ ...
- WebService之CXF注解报错(二)
WebService之CXF注解 1.具体报错如下 五月 04, 2014 11:24:12 下午 org.apache.cxf.wsdl.service.factory.ReflectionServ ...
- C++与Java通过WebService通信(上)
一. 前言 本篇讲述如果通过C++客户端访问Java服务端发布的SOAP模式的WebService接口.文档中的样例代码拷贝出去即可运行,所有的代码都是本地测试OK的:本文不但解决了接口调用的问题,同 ...
随机推荐
- Java中的代码块
代码块 普通代码块 构造代码块 静态块 同步代码块 普通代码块 为了在方法里面编写过多的变量,防止变量重复,可以用代码块进行隔离. package org.lyk.main; public class ...
- lucene-源码分析
lucene-源码分析 http://www.cnblogs.com/forfuture1978/p/3940965.html
- java socket通讯(一) 入门示例
一.入门 要想学习socket通讯,首先得知道tcp/ip和udp连接,具体可参考浅谈TCP/IP 和 UDP的区别 二.示例 首先新建了一个java工程,包括两个部分,客户端SocketClient ...
- spring的框架集,简化的编程模型
spring batch spring intergration spring ws spring jms spring-mvc -> spring-rest resthate z
- sizeof usage & big / little endian
http://blog.csdn.net/w57w57w57/article/details/6626840 http://people.cs.umass.edu/~verts/cs32/endian ...
- sqlserver添加用户的时候出现 错误18456
1.用本机默认的window身份验证登录 2.登录成功后,在数据库->安全性->登录名->右键属性->如图选择“新建登录名” 3.在如图所示的登录名中,输入将要新建的登录用户, ...
- iphone显示信号强弱(field test)
第一步,进入[电话]第二步,在拨号键盘上输入*3001#12345#*,然后按下[呼叫]按钮,iOS内置应用Field Test就被启动了,同时左上角也出现了信号强度的精确值. 第三步,按住iPhon ...
- OC基础(17)
ARC基本概念 ARC快速入门 ARC下的内存管理 ARC和MRC兼容和转换 *:first-child { margin-top: 0 !important; } body > *:last- ...
- 点评App wiki-git标准实践
fetch与pull fetch = pull + merge fetch -p,用于将清理工作同步到本地repository rebase-衍合 merge与rebase是合并的两种方法(上为mer ...
- 前端开发 Grunt 之 Connect
在前端开发过程中,我们需要在开发过程中,将开发中的站点部署到服务器上,然后,在浏览器中查看实际的效果,在 Grunt 环境下,可以直接使用集成在 Grunt 中的 Connect 插件完成站点服务器的 ...