项目场景:
使用 Spring Boot 暴露 WebService 接口.
| gav |
|---|
| org.springframework.boot:spring-boot-starter-web-services:2.1.13.RELEASE |
| org.apache.cxf:cxf-spring-boot-starter-jaxws:3.3.6 |
| org.apache.cxf:cxf-rt-transports-http:3.3.6 |
问题描述:
2021-05-17 10:46:56.613 ERROR 195180 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
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.
原因分析:
@Configuration
public class CXFConfig {
@Bean
public ServletRegistrationBean dispatcherServlet() {
return new ServletRegistrationBean(new CXFServlet(), "/webservices/*");
}
}
CXFConfig配置类里注册 Servlet 的 Bean 的 name 是dispatcherServlet,造成错误的。
因此需要调整注册的 Servlet 的 Bean 的名称。
解决方案:
调整注册的 Servlet 的 Bean 的名称,避免Bean(name = "dispatcherServlet")
@Configuration
public class CXFConfig {
@Bean
public ServletRegistrationBean cxfServlet() {
return new ServletRegistrationBean(new CXFServlet(), "/webservices/*");
}
}
参考
springboot整合cxf启动报错,原因是版本问题 - https://princeyao.blog.youkuaiyun.com/article/details/113177336
本文解决了一个关于SpringBoot项目中整合CXF时遇到的启动失败问题。具体表现为因Servlet Bean名称冲突导致的错误,并提供了修改Bean名称的解决方案。
4100

被折叠的 条评论
为什么被折叠?



