1.导入cxf jar包集成了spring jar \apache-cxf-2.4.2\apache-cxf-2.4.2\lib 所以jar
2.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"> <!-- 配置spring 监听器 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:cxf-servlet.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- 配置CXF的核心Servlet --> <servlet> <servlet-name>cxf</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> <!-- 通过初始化参数指定cxf配置文件的位置 --> <!-- <init-param> <param-name>config-location</param-name> <param-value>classpath:cxf-servlet.xml</param-value> </init-param> --> </servlet> <servlet-mapping> <servlet-name>cxf</servlet-name> <url-pattern>/cxf/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
3.编写服务端代码
package cn.my.cxf; import javax.jws.WebService; import javax.xml.ws.BindingType; import javax.xml.ws.soap.SOAPBinding; //别忘了加注解 @WebService public class HelloService { public String sayHello(String name){ System.out.println("正在调用sayHello方法"); return "hello " + name; } }
4.spring配置文件如下:
<?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" xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd"> <!-- 引入CXF Bean定义如下,早期的版本中使用 --> <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" /> <!-- 第一种发布方式:简单发布(没有接口的发布) --> <!-- id:唯一标示 implementor:提供服务的类 address:服务的请求url--> <jaxws:endpoint id="helloService" implementor="cn.my.cxf.HelloService" address="/hello"> </jaxws:endpoint> </beans>
5.访问wsdl
成功
相关推荐
cxf+spring实现webservice
这个是cxf+spring发布webservice和restservice的服务端项目
CXF+Spring+Tomcat发布WebService
CXF3.1+Spring4.1发布webservice服务的例子,内附说明,方便以后自己回顾这个过程。里面已经包含必须引用的jar包,不用再到处去收集。
cxf+spring开发webservice的简单实例,通过查看cfx的doc文档确定wsdl支持所引用的最少jar包
Spring+CXF+tomcat开发webservice,包含服务端和客户端,导入myeclipse就可以用。帮助大家搭建webservice框架,实现webservice功能。
简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar...
CXF+Spring+Hibernate实现WebService,实现的方法比较简单,只有一个增加的方法,没有用到Struts 有服务端代码和客户端测试代码
这个是cxf 集成spring 的webservice的例子 供大家参考
cxf+spring实现webservice的例子,在eclipse开发环境上测试通过,由于上传限制,没有传lib,只把代码上传了,有需要的可以给我留言,我给单发!
CXF+spring+struts实现WebService
CXF+Tomat发布WebService没有Spring
cxf+spring+tomat开发webservice所需jar包,该jar包只需解压后导入web工程即可,亲测有用
使用cxf+spring框架开发webservice的客户端与服务端代码,用于连接两个项目
web项目使用spring和cxf的一个开发实例,有简单的代码样例和jar。是一个完整的项目,最终发布完成时访问 http://ip:port/项目名称/webservices/ 就会发现你发布的webservice服务。
ibatis+spring+cxf+mysql搭建webservice的客户端,文章地址在http://blog.csdn.net/cenyi2013/article/details/17315755. 服务端源码的下载地址在http://download.csdn.net/detail/cenyi2012/6712729
本文主要运用当前比较流行的cxf+spring是想webservice的一个小的demo,在网上搜了许多的资料,最后经过自己的理解实现
cxf+spring webService实例,用到的包自己导入吧!
这里少了一个类,是根据实体类生成xml的文件下载地址为:http://download.csdn.net/detail/qq_14996421/9495688
cxf+spring+jdk1.5开发webService部署weblogic9.2