首页 > Web开发 > 详细

使用CXF生成webservice

时间:2017-03-01 12:34:03      阅读:162      评论:0      收藏:0      [点我收藏+]

1.使用cxf生成webservice,引入cxf jar包,在pom.xml中添加依赖即可:

<!--CXF--!>
<dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-bundle</artifactId> </dependency>

2.定义一个webservice服务的客户端:

com.abc.webservice
import
javax.jws.WebMethod; import javax.jws.WebResult; import javax.jws.WebService; /** * 毕业生认证webservice服务的客户端 * * @author * */ @WebService(targetNamespace = "http://www.abc.com") public interface BysRzServerService { /** * 查询毕业生信息(毕业生认证) * * @param xm * 姓名 * @param byzh * 毕业生号 * @return RspBean */ @WebMethod(operationName = "bysRz") @WebResult(name = "result") public String bysRz(String xm,String byzh) throws Exception; }

注:WebMethod(operationName="bysRz")即为webservice的方法名,WebResult(name="result")表示webservice返回值

@WebService(endpointInterface="com.abc.webservice.BysRzServerService")
public class BysRzServerServiceImpl implements BysRzServerService {
    private static final Log log = LogFactory.getLog(BysRzServerServiceImpl.class);
    
    /**
     * 毕结业综合查询service
     */
    @Override
    public String bysRz(String xm, String byzh) throws Exception {
        //进行业务逻辑处理,将处理结果返回
        StringBuffer sb=new StringBuffer("");
        return sb.toString();
    }
    
}

3.在spring-webservice.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"
    xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://cxf.apache.org/jaxws
        http://cxf.apache.org/schemas/jaxws.xsd
        http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd ">  
    <!--认证webservice -->
  <jaxws:server id="bysRzServerService" serviceClass="com.abc.webservice.BysRzServerService"
            address="/bysRzServerService" >
            <jaxws:serviceBean>
                <bean class="com.abc.webservice.BysRzServerServiceImpl">
                    <property name="bysZhcxService" ref="bysZhcxService"/><!--该处为业务逻辑处理需要使用的bean对象-->
                </bean>
            </jaxws:serviceBean>        
    </jaxws:server>

  //另一种配置方法

  <jaxws:endpoint id="bysRzServerService"

    implementorClass="com.abc.webservice.BysRzServerService"

    address="/bysRzServerService">

    <jaxws:implementor>
      <bean  class="
com.abc.webservice.BysRzServerServiceImpl">

        <property name="imDealDeptUserService" ref="imDealDeptUserService" />
      </bean>
    </jaxws:implementor>
  </jaxws:endpoint>

</beans>

4.将spring-webservice.xml文件引入到applicationContext.xml中,在web.xml中配置CXF的servlet配置:

  

<!-- CXF -->
    <servlet>
        <servlet-name>CXFServlet</servlet-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>

5.通过ip可以测试webservice是否成功:http://localhost:8088/项目名称/webservice/bysRzServerService?wsdl

使用CXF生成webservice

原文:http://www.cnblogs.com/zijinyouyou/p/6483273.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!