当前位置: 首页 > 工具软件 > ER Framework > 使用案例 >

【Exception】Parameter 1 of constructor in org.springframework.boot.autoconfigure.web.servlet.error.Er

田德馨
2023-12-01

项目场景:

使用 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.csdn.net/article/details/113177336

 类似资料: