springboot整合CXF时,启动报错

Spring boot版本:2.2.0.M4
CXF版本:3.3.3
报错内容:

***************************
APPLICATION FAILED TO START
***************************
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.
The following candidates were found but could not be injected:
    - Bean method 'dispatcherServletRegistration' in 'DispatcherServletAutoConfiguration.DispatcherServletRegistrationConfiguration' 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.

报错原因:Spring boot版本太高
报错的代码处:

@Bean
    public ServletRegistrationBean dispatcherServlet() {
        return new ServletRegistrationBean(new CXFServlet(), "/cxf/*");// 发布服务名称 localhost:8080/cxf
    }

修改方法:
方法一:降低Spring boot版本,至2.0以下
方法二:删除上面报错代码处,并在application.yml中添加如下配置:

cxf:
  path: /cxf  

访问路径:localhost:8080/cxf/hello?wsdl

你可能感兴趣的:(springboot整合CXF时,启动报错)