spring boot 集成 cxf 发布webService服务,配置类 需要注意的问题

88 阅读1分钟
  1. cxf的配置类代码
@Configuration
public class CxfConfig {
 
    //默认servlet路径
    @Bean
    public ServletRegistrationBean webServiceDispatcherServlet() {
        return new ServletRegistrationBean(new CXFServlet(), "/webService/*");//接口路径包含/webService
    }
 
    @Autowired
    Bus bus;
 
    @Autowired
    BookService bookService;
 
    @Autowired
    GoodsService goodsService;
 
    @Bean
    @ConditionalOnProperty(value = "myWebService.name", havingValue = "goodsService", matchIfMissing = false)
    public Endpoint goodsService() {
        EndpointImpl endpoint = new EndpointImpl(bus,goodsService);
        //接口发布在 /goodsService 目录下,访问路径为/webService/goodsService?wsdl
        endpoint.publish("/goodsService");
        return endpoint;
    }
 
    @Bean
    @ConditionalOnExpression("'${myWebService.name}' == 'bookService' or '${myWebService.name}' == 'goodsService'")
    public Endpoint bookService() {
        EndpointImpl endpoint = new EndpointImpl(bus,bookService);
        endpoint.publish("/bookService");//接口发布在 /bookService 目录下
        return endpoint;
    }
}
  1. 配置类的两个问题
    1. 注入bean的名称不能是dispatcherServlet,否则会跟spring boot 冲突报异常。
    1. webService映射路径不要设置为/*,否则会拦截所有的请求,导致http请求被拦截。