- cxf的配置类代码
@Configuration
public class CxfConfig {
@Bean
public ServletRegistrationBean webServiceDispatcherServlet() {
return new ServletRegistrationBean(new CXFServlet(), "/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);
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");
return endpoint;
}
}
- 配置类的两个问题
-
- 注入bean的名称不能是dispatcherServlet,否则会跟spring boot 冲突报异常。
-
- webService映射路径不要设置为/*,否则会拦截所有的请求,导致http请求被拦截。