webserveice搭建

第一步导入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.xml中url-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;

    }

}

 

 

 

 

 

发布

 

public class Test {

 public static void main(String str[] ) {
  
  System.out.println("Starting Server");
        Service helloWorldServiceImpl=new Service();
        String address="http://localhost:8090/TestCXF";
        Endpoint.publish(address, helloWorldServiceImpl);
        System.out.println("Start success");

注:TestCXF为你的项目名称

 

 

 

测试

 

 

 

public class TestClient {

 
 public static void main(String[] args) {
  
  JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
  factory.getInInterceptors().add(new LoggingInInterceptor());
  factory.getOutInterceptors().add(new LoggingOutInterceptor());
  factory.setServiceClass(IService.class);
  factory.setAddress("http://localhost:8090/TestCXF/services/test");
  IService client = (IService) factory.create();
  String msg = client.test("kinglo");
  System.out.println(msg);

 

注:servieces是web.xml中配置的url  test是访问地址

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值