CXf 创建webservice

来源:互联网 发布:阿里云金牌合作伙伴 编辑:程序博客网 时间:2024/06/05 08:58
 
//定义接口
import javax.jws.WebMethod;import javax.jws.WebParam;import javax.jws.WebResult;import javax.jws.WebService;@WebServicepublic interface IUserWebService {@WebMethodpublic @WebResult(name = "String") String select(@WebParam(name = "name") String name); }
//实现接口

import java.util.List;

import javax.annotation.Resource;

import com.hengtong.web.service.SysService;import com.hengtong.web.util.JsonToString;import com.hengtong.web.view.domain.ModuleView;

public class UserWebService implements IUserWebService { private SysService sysService; @Resource(name = "sysService") public void setSysService(SysService sysService) {  this.sysService = sysService; } public String select(String name) {    return name; }}

spring-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:context="http://www.springframework.org/schema/context" 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://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd   http://cxf.apache.org/jaxws    http://cxf.apache.org/schemas/jaxws.xsd">

 <!--CXF配置-->          <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"/>           <!--服务端发布的webservice-->           <jaxws:endpoint id="userWebService" implementor="com.hengtong.web.webservice.UserWebService" address="/UserWebService"/>           <!--客户端调用的webservice-->           <jaxws:client id="userWebServiceClient"  address="http://localhost:8080/项目名称/webservice/UserWebService" serviceClass="com.hengtong.web.webservice.IUserWebService"/></beans>

 

web.xml

 

<!--添加以下代码-->

 

 

 <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>

 

cxf 所需要的jar