标签:spring webservice cxf
一、web project整合spring
1.1、打开Myeclipse,建立web project(eclipse为dynamic web project),使用J2EE5.0。
1.2、添加Srping的基本jar包(无需事务等)
org.springframework.beans-3.1.1.RELEASE.jar
commons-logging.jar org.springframework.aop-3.1.1.RELEASE.jar org.springframework.asm-3.1.1.RELEASE.jar org.springframework.beans-3.1.1.RELEASE.jar org.springframework.context-3.1.1.RELEASE.jar org.springframework.context.support-3.1.1.RELEASE.jar org.springframework.core-3.1.1.RELEASE.jar org.springframework.expression-3.1.1.RELEASE.jar org.springframework.orm-3.1.1.RELEASE.jar org.springframework.web-3.1.1.RELEASE.jar
1.3、新建源文件夹(source folder)conf,位于项目下,添加applicationContext.xml到该目录,内容如下:
<?xml version="1.0"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" 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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd "> </beans>
1.4、在web.xml中web-app节点下添加监听,如下:
<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>
运行项目,正常运行则说明正常。
二、开发webservice服务
新建RegeditService类,如下:
package zxn.ws.service; import javax.jws.WebParam; import javax.jws.WebService; @WebService public interface RegeditService { /** * 注册方法 * @param username * @param password * @return */ public String regedit(@WebParam(name = "username")String username, @WebParam(name="password")String password); }新建RegeditServiceImpl类,如下:
package zxn.ws.service; import javax.jws.WebService; @WebService(endpointInterface="zxn.ws.service.RegeditService",serviceName="Regedit", targetNamespace="http://service.ws.zxn/") public class RegeditServiceImpl implements RegeditService { /** * 注册方法 * @param username * @param password * @return */ public String regedit(String username, String password) { return username+",你已成功注册!"; } }
三、spring整合cxf
3.1、添加jar包
cxf-2.7.8.jar neethi-3.0.2.jar xmlschema-core-2.0.3.jar wsdl4j-1.6.3.jar asm-3.3.jar3.2、applicationContext.xml中添加如下内容:
<import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <!-- webservice配置 ,myeclipse可能检测到此处有错没影响--> <jaxws:endpoint id="regeditService" implementor="zxn.ws.service.RegeditServiceImpl" address="/Regedit" />3.3、在web.xml中添加如下cxf配置:
<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>/services/*</url-pattern> </servlet-mapping>
wsdl文档如下图:
另附上源代码地址:http://download.csdn.net/detail/zxnlmj/7457693
使用CXF+spring创建一个web的接口项目,布布扣,bubuko.com
标签:spring webservice cxf
原文地址:http://blog.csdn.net/zxnlmj/article/details/28880303