一,首先是准备工作,所需要的jar包:
cxf-2.4.1.jar
neethi-3.0.0.jar
xmlschema-core-2.0.jar
wsdl4j-1.6.2.jar
geronimo-activation_1.1_spec-1.1.jar
geronimo-annotation_1.0_spec-1.1.1.jar
geronimo-javamail_1.4_spec-1.7.1.jar
geronimo-servlet_3.0_spec-1.0.jar
geronimo-ws-metadata_2.0_spec-1.1.3.jar
jaxb-api-2.2.1.jar
jaxb-impl-2.2.1.1.jar
jaxb-xjc-2.2.1.1.jar
jetty-http-7.4.2.v20110526.jar
jetty-server-7.4.2.v20110526.jar
jetty-util-7.4.2.v20110526.jar
saaj-api-1.3.jar
saaj-impl-1.3.2.jar
wss4j-1.6.1.jar
xmlbeans-2.4.0.jar
红色部分是不集成spring开发调试需要用到的jar包,spring需要的包一般spring工程都会有,这里不做说明。
二,创建service接口和实现类
接口:
@WebService
public interface HelloWorld {
String sayHello(@WebParam(name="text") String text);
}
实现类:
@WebService(endpointInterface="com.***.***.webservice.test.HelloWorld",serviceName="helloword" )
@Component(value="helloWorld")
public class HelloWordImpl implements HelloWorld {
public String sayHello(String text) {
return "Hello, "+text;
}
}
二,配置web.xml过滤.
在工程的web.xml添加如下内容:
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXFServlet</display-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/webservice/*</url-pattern>
</servlet-mapping>
三,集成到spring,定义bean及访问服务的URL等,通过spring发布服务。
在这为使得配置清晰分明,新建一个applicationContext-cxf.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:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.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"/>
<jaxws:endpoint
id="sayhello"
implementor="#helloWorld"
address="/helloWorld" />
<jaxws:client id="client"
serviceClass="com.***.**.webservice.test.HelloWorld"
address="http://localhost:8080/webservice/helloWorld" />
</beans>
将上面的文件引入到applicationContext.xml中:
<import resource="applicationContext-cxf.xml"/>
启动服务,在地址栏访问 http://localhost:8080/webservice/helloWorld?wsdl,若成功,则能看到一段wsdl的xml信息。
客服端根据wsdl的信息生成客户端的代码。
非集成spring发布服务代码如下:
import javax.xml.ws.Endpoint;
import com.***.***.webservice.test.impl.HelloWordImpl;
public class WebServiceApp {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("web service start");
HelloWordImpl implementor= new HelloWordImpl();
String address="http://localhost:8080/helloWorld";
Endpoint.publish(address, implementor);
System.out.println("web service started");
}
}
分享到:
相关推荐
cxf+spring实现webservice
CXF和Spring搭建webservice代码
使用cxf+spring框架开发webservice的客户端与服务端代码,用于连接两个项目
web项目使用spring和cxf的一个开发实例,有简单的代码样例和jar。是一个完整的项目,最终发布完成时访问 http://ip:port/项目名称/webservices/ 就会发现你发布的webservice服务。
cxf与spring整合webservice所需jar
这个是cxf+spring发布webservice和restservice的服务端项目
cxf+spring开发webservice的简单实例,通过查看cfx的doc文档确定wsdl支持所引用的最少jar包
cxf与spring发布WebService
Cxf集成Spring的WebService接口的配置文档
linux环境下,cxf整合spring发布webservice源码
Spring+CXF+tomcat开发webservice,包含服务端和客户端,导入myeclipse就可以用。帮助大家搭建webservice框架,实现webservice功能。
CXF2+Spring2.5开发WebService实例,需要导入jar包
cxf+spring实现webservice的例子,在eclipse开发环境上测试通过,由于上传限制,没有传lib,只把代码上传了,有需要的可以给我留言,我给单发!
这个是cxf 集成spring 的webservice的例子 供大家参考
本java工程实现了spring+cxf快速开发webservice jar包齐全导入myeclipse可直接二次开发
本实例工程使用Apache CXF组件快速开发WebService。基于Spring框架,使用了Maven项目,但由于时间原因,只使用了Maven Project的框架,还是使用lib文件夹存放所需的cxf库,传入传出对象支持Json格式。
本文主要运用当前比较流行的cxf+spring是想webservice的一个小的demo,在网上搜了许多的资料,最后经过自己的理解实现
cxf+spring+tomat开发webservice所需jar包,该jar包只需解压后导入web工程即可,亲测有用
使用cxf和spring开发基于https的webservice服务端以及客户端样例
用CXF开发RESTful风格WebService.doc