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的:本文不但解决了接口调用的问题,同 ...
随机推荐
- Linux有问必答:怎样解决“XXX is not in the sudoers file”错误
问题:我想在我的Linux系统上使用sudo来运行一些特权命令,然而当我试图这么做时,我却得到了"[我的用户名] is not in the sudoers file. This incid ...
- Python进阶02 文本文件的输入输出
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! Python具有基本的文本文件读写功能.Python的标准库提供有更丰富的读写功能 ...
- 使用bs4对海投网内容信息进行提取并存入mongodb数据库
example: http://xyzp.haitou.cc/article/722427.html 首先是直接下载好每个页面,可以使用 os.system( "wget " ...
- UITapGestureRecognizer 的用法
最近在项目中用到了手势操作,键盘回收时还是挺常用的,现在总结下,多谢网络上大神们的分享. 先分享下我在项目中用的代码: UITapGestureRecognizer * mytap=[[UITapGe ...
- [ActionScript 3.0] AS3 用于拖动对象时一次一页的缓动
package com.fylibs.components.effects{ import com.tweener.transitions.Tweener; import flash.display. ...
- role在标签中的作用是什么?
html 里面的 role 本质上是增强语义性,当现有的HTML标签不能充分表达语义性的时候,就可以借助role来说明.通常这种情况出现在一些自定义的组件上,这样可增强组件的可访问性.可用性和可交互性 ...
- 四个排名函数(row_number、rank、dense_rank和ntile)的比较
排名函数是SQL Server2005新加的功能.在SQL Server2005中有如下四个排名函数: 1.row_number 2.rank 3.dense_rank 4.ntile 下面分别介绍一 ...
- Delphi中自画TStatusBar面板中的文字颜色背景以及图片
转自 http://www.delphitop.com/html/kongjian/351.html 首先定义:procedure TStatusForm.FormCreate(Sender: TOb ...
- Entity Framework6 访问MySQL
先用PM命令安装EF6,MySQL提供的EF实现新增.删除.修改是采用存储过程实现的 Install-Package EntityFramework 配置修改如下 <?xml version=& ...
- Net文章汇总帖
DevExpress:Data Grid ExamplesHow to: Initialize Cells in Newly Created RowsHow to: Set a Cell Value ...