1、首先下载 http://people.apache.org/dist/incubator/cxf/2.0.4-incubator/apache-cxf-2.0.4-incubator.zip
cxf 开发包
cxf 集成spring 解压包后 里面包括,spring 包 comms 其他包。
拷入jar包
拷入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:spring-cxf-server.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>/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
spring-cxf-server.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.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<!-- cxf 服务器端,用于创建并发布服务 -->
<!-- 一下三个文件位于cxf-2.1.12.jar中 -->
<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" />
<!-- 当web服务器启动的时候会创建并发布该服务 启动日志信息如下: 信息: Creating Service {http://impl.service.cxf.com/}Helloworld
from class com.cxf.service.iface.Helloworld 2010-12-31 14:18:48 org.apache.cxf.endpoint.ServerImpl
initDestination 信息: Setting the server's publish address to be /myService -->
<jaxws:endpoint id="Helloworld" implementor="com.cxf.service.impl.HelloworldImpl" address="/myService" />
</beans>
接口
package com.cxf.service.iface;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService
public interface Helloworld {
public String sayHello(@WebParam(name="text") String text);
}
实现
package com.cxf.service.impl;
import javax.jws.WebService;
import com.cxf.service.iface.Helloworld;
@WebService(serviceName = "Helloworld")
public class HelloworldImpl implements Helloworld {
public String sayHello(String text) {
return "hello " + text;
}
}
访问:
http://localhost:8080/sgh_publish_platform/myService/sayHello/text/my-namy-is-leiwuluan
客户端:
ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-cxf-client.xml");
Helloworld helloworld = (Helloworld) ctx.getBean("helloworldClient");
String info = helloworld.sayHello("taoge11111");
System.out.println(info);
<?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.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<!-- cxf 客户端 -->
<jaxws:client id="helloworldClient" serviceClass="com.cxf.service.iface.Helloworld"
address="http://localhost:8080/cxf/myService" />
</beans>
分享到:
相关推荐
cxf spring maven 实例 webservice
简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar...
基于maven的cxf+spring简单demo,spring版本为4.1.6,cxf版本为3.0.8
webservice cxf spring整合返回list,bean,string,json,xml项目完整实例
利用CXF3.0+Spring3.2 HelloWorld实例,并且导入了小量的jar包以及在写例子的过程中遇见的一些错误!
webserivce.、cxf整合spring,用的是spring3和cxf3。欢迎大家下载尝试
Spring CXF Restful 实例
CXF Spring Web Service 程序,希望对大家有用!!
使用cxf+spring框架开发webservice的客户端与服务端代码,用于连接两个项目
CXF结合spring项目实例,com.email.ws.impl包下为eclipse工具生成的客户端,text包用来测试
使用CXF开发简单HelloWorld实例
cxf+spring实现webservice
cxf与Spring一个简单的小例子,希望多初学者有所帮助。不明白的联系我
利用CXF和Spring结合搭建的SOA例子,内容包含服务端配置和一个客户端测试配置,服务器端服务配置在beans.xml中,web.xml文件需要修改;客户端测试配置地址是demo.spring.client下的client-beans.xml,测试类为...
CXF Restful服务简单例子
cxf+spring整合,只要把项目导入到myeclipse中,就可以运行。
内容为CXF整合spring的服务端和客户端开发例子,注释不太详尽,网上的教程比较多,但是多跑不起来,特地把整个工程都打包给大家做参考,程序内容均来自网上整理,均可以运行。
CXF2+Spring2.5开发WebService实例,需要导入jar包
CXF&spring实例,服务端客户调,spring配置