微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

cfx webService 入门详细步骤

 

第一步 导入cfx相关包 下载地址: http://cxf.apache.org/download.html

 

第二步 配置web.xml

<!-- cfx webSerivice -->

    <servlet> 

    <description>Apache CXF Endpoint</description> 

    <display-name>cxf</display-name> 

    <servlet-name>cxf</servlet-name> 

    <servlet-class>

org.apache.cxf.transport.servlet.CXFServlet

</servlet-class> 

    <load-on-startup>1</load-on-startup> 

    </servlet> 

    <servlet-mapping> 

      <servlet-name>cxf</servlet-name> 

      <url-pattern>/services/*</url-pattern> 

    </servlet-mapping> 

    <session-config> 

      <session-timeout>60</session-timeout> 

    </session-config>

第三步 web-inf下加入cfx-servlet.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:soap="http://cxf.apache.org/bindings/soap"

      xsi:schemaLocation="

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd

http://cxf.apache.org/jaxws

http://cxf.apache.org/schemas/jaxws.xsd">

<!-- ;服务接口  -->

  <jaxws:server id="jaxwsService" serviceClass="com.uu.service.IService"

address="/test"> <!—address为服务发布二级地址 完整地址 /项目发布名称/cfx拦截地址/address   (cfx拦截地址在web.xmlurl-pattern标签中配置) -->

       <jaxws:serviceBean>

        <!--服务实现类  -->

                <bean class=" com.uu.service.impl.Service " />

       </jaxws:serviceBean>

  </jaxws:server>

</beans>

第四步 编写接口及实现类

IService 接口

package com.uu.service;

@WebService

public interface IService

{

   

    @WebMethod

    String test(@WebParam String param);

 }

Service实现类:

package com.uu.service.impl;

public class QuoteService implements IQuoteService

{

    @Override

    public String test(String param)

    {

       return "Hello,"+param;

    }

 

}

第五步     单元测试

@Test

public void test3()

{

    JaxWsProxyfactorybean factory = new JaxWsProxyfactorybean(); 

    factory.getininterceptors().add(new LoggingInInterceptor()); 

    factory.getoutInterceptors().add(new LoggingOutInterceptor()); 

    factory.setServiceClass(IService.class); 

    factory.setAddress("http://localhost:8081/项目名称/services/test"); 

    IService client = (IService) factory.create();

    String msg =  client.test("kinglo");

    System.out.println(msg);

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐