最近开发springboot整合cxf,以及springboot升级发现了很多烦人的问题,在此记录一下:
刚开始用的springboot版本是1.5.12,后来升级为springboot 2.0.4.
配置cxf如下:
@Configuration
public class WebServiceConfig {
@Bean
public ServletRegistrationBean dispatcherServlet() {
return new ServletRegistrationBean(new CXFServlet(), "/webservice/*");
}
@Bean(name = Bus.DEFAULT_BUS_ID)
public SpringBus springBus() {
return new SpringBus();
}
@Bean
public UMIServiceSoap uMIServiceSoap() {
return new UMIServiceSoapImpl();
}
@Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(springBus(), uMIServiceSoap());
endpoint.publish("/XXService");
return endpoint;
}
}
然后启动项目报错:
Description:
Parameter 1 of constructor in org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration required a bean of type 'org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath' that could not be found.
- Bean method 'dispatcherServletRegistration' not loaded because DispatcherServlet Registration found non dispatcher servlet dispatcherServlet
Action:
Consider revisiting the entries above or defining a bean of type 'org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath' in your configuration.
网上查了半天,一无所获,不断尝试不同的springboot版本,最终发现2.0.3没有问题,2.0.4之后的版本都有这个问题。
把版本调成2.0.3后,发现新的问题。就是配置了
后,webservice访问没有问题,但是controller都访问不到,经网上查找可通过在application.properties或者application.yml配置
cxf.path=/webservice
解决问题,这样就不用在代码中配置dispatcherServlet()。
这样的话是不是springboot版本的问题就解决了呢?
进过测试springboot2.0.4版本启动、webservice访问、controller访问都没有问题了。
解决controller和webservice访问的问题是看了下面的博客,在此谢谢大牛:
spring boot 集成cxf时Controller映射报错的坑