解决SpringBoot集成Apache CXF 发布服务端后,客户端调用不了的问题

解决SpringBoot集成Apache CXF 发布服务端后,客户端调用不了的问题

先说解决方法:

​ 在META-INF中创建services文件夹, 以Provider这个类的全名来新建立一个文件,文件中的内容为指定实现类的全名,如下:在这里插入图片描述

问题背景:

​ 项目涉及到周边老系统的数据交互,采用webService的方式。调用webService有很多方式,我采用了最偷懒的方式–idea生成客户端代码(就此埋下了坑)。

​ 后来需求增加功能,需要发布一个WebService服务接收周边系统下发的数据。(周边系统老的一批)。因为是SpringBoot项目,并且SpringBoot对Apache CXF也有很好的支持,所以我选择了cxf。架构大概如下:

项目架构:
  1. Springboot 2.1.1.RELEASE

            <parent>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>2.1.1.RELEASE</version>
            </parent>
    		<dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-aop</artifactId>
            </dependency>+
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
  2. cxf依赖

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
        <version>3.3.4</version>
    </dependency>
    
  3. 配置类

    /**
     * @MathodName
     * @Description
     * @Author jiangying
     * @Params
     * @Returns
     * @Data 2020/3/18
     */
    @Configuration
    public class CxfConfig {
         
    
        //webService接口类
        @Autowired
        private CertinoticeService certinoticeService;
    
        //webService接口类
        @Autowired
        private UnderwriteService underwriteService;
    
        @Bean(name = Bus.DEFAULT_BUS_ID)
        public SpringBus springBus() {
         
            SpringBus springBus = new SpringBus();
            return springBus;
        }
    
        @Bean
        public Endpoint certEndpoint(){
         
            EndpointImpl certEndpoint = new EndpointImpl(springBus(), certinoticeService);
            //服务路径(http://xxx.com/services/CertinoticeService)
            certEndpoint.publish("/CertinoticeService");
            return certEndpoint;
        }
    
        @Bean
        public Endpoint anotherEndpoint(){
         
            EndpointImpl underEndpoint = new EndpointImpl(springBus(), underwriteService);
            //服务路径
            underEndpoint.publish("/UnderwriteService");
            return underEndpoint;
        }
    }
    

启动正常访问,完美(才怪)

在这里插入图片描述

服务端访问是没有问题,可是突然发现自己原来的客户端都访问不了了:

javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException
	at org.apache.cxf.jaxws.ServiceImpl.getPort(ServiceImpl.java:360)
	at org.apache.cxf.jaxws.ServiceImpl.getPort(ServiceImpl.java:349)
	at javax.xml.ws.Service.getPort(Service.java:119)
	at com.ccic.salesapp.customer.outService.esb.ecif.custCarInfoSearch.intf.CustCarInfoSearchService.getCustCarInfoSearchEndpoint(CustCarInfoSearchService.java:75)
	at com.ccic.salesapp.customer.utils.WebServiceUtils.doCustCarInfoSearchRequest(WebServiceUtils.java:304)
	at com.ccic.salesapp.customer.controller.CustomerServeController.test(CustomerServeController.java:45)
	at com.ccic.salesapp.customer.controller.CustomerServeController$$FastClassBySpringCGLIB$$2ef4d2d9.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值