webService中的CXF实现

我记录的是工作中所用到的,只是把我看到的理解的记录一下,仅供参考(...),所记录的不是特别详细,所以我找到了一篇自认为特别详细的介绍:

https://blog.csdn.net/hgx_suiyuesusu/article/details/88918192 

https://blog.csdn.net/csdn_gia/article/details/54863549

https://www.cnblogs.com/yongfeng/archive/2013/01/30/2883146.html

感觉把我想写的都写了,哈哈

我也是菜鸟,需要不断的积累和学习,加油.

导入cxf的依赖:

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>3.1.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>3.1.6</version>
        </dependency>

我们这里主要是通过注解配置,web service的配置类

/**
 * webService配置类
 * @author 这是公司大佬写的
 */
@Configuration
public class CxfConfig {
    @Bean
    public ServletRegistrationBean servletRegistrationBean() {
        return new ServletRegistrationBean(new CXFServlet(), "/services/*"); 
      //ServletName默认值为首字母小写,即myServlet  访问的时候就是需要访问这个localhost:8081/项目名/services
    }

    @Bean
    public MakeSealSystem makeSealSystem(){ // 这里是webService实现类
        return new MakeSealSystem();
    }

   
    @Bean
    public Endpoint makeSealEndpoint() { // 这里是访问界面中的地址
        EndpointImpl endpoint = new EndpointImpl(springBus, makeSealSystem());
        endpoint.publish("/makeSealSystemService");
        return endpoint;
    }


    @Bean
    public MakeSealSystemProcess makeSealSystemProcess() { // 这里是调用webservice实现类中的类
        return new MakeSealSystemProcess();
    }

  

    @Autowired
    SpringBus springBus; // 这个是EndpointImpl实现类所需要的
}

上面注入的springBus主要是这个功能:

它的主要责任是提供对不同扩展名(例如DestinationFactoryManager,ConduitFactoryManager,BindingFactoryManager等)的访问。 根据总线的实现,它也可能负责连接CXF内部。

web service的实现类:

/**
 * 制作系统webService实现类
 * @author 这是公司美丽的小姐姐写的
 */
@WebService
public class MakeSealSystem {

    // 这个里面的makeSealSystemProcess是一个具体的实现逻辑的类
    @WebMethod
    public String applySealCode(@WebParam(name = "requestStr") String requestStr) throws Exception {
        long beginTime=System.currentTimeMillis();
        String result = ((MakeSealSystemProcess) Util.getBean("makeSealSystemProcess")).applySealCode(requestStr,beginTime,getRequest());
        return result;
    }

    private HttpServletRequest getRequest() {
        MessageContext ctx = context.getMessageContext();
        HttpServletRequest request = (HttpServletRequest) ctx.get(AbstractHTTPDestination.HTTP_REQUEST);
        return request;
    }

    @Resource
    private WebServiceContext context;

}

 看访问的结果:http://localhost:8081/项目名称/services/

点击上面的链接可以看到具体的内容:

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值