Error creating bean with name 'servletEndpointRegistrar' defined in class path resource

本文详细解析了在Spring Boot应用中遇到的“Error creating bean with name ‘servletEndpointRegistrar’”错误,深入探讨了该问题的根本原因在于数据源配置缺失或JDBC驱动配置不当,并提供了具体的解决方案,包括正确配置数据源属性和添加必要的JDBC依赖。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

记一次配置内容丢失导致报错问题:Error creating bean with name ‘servletEndpointRegistrar’ defined in class path resource …

  • 报错内容:
 Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: 
	
	
 Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: 
	
 Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: 
	
	
 Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException:
	
	
	
 Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthEndpoint]: Factory method 'healthEndpoint' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: 
	
	
 Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration':
 Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: 
	
	
 Failed to instantiate [org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration$$EnhancerBySpringCGLIB$$caa88ea6]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: 
	
 Error creating bean with name 'dataSource': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: 
	
 Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
  • 问题关键在最后一句:
   Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class

笔者也是在Error creating bean with name ‘servletEndpointRegistrar’ defined in class path resource
报错纠结许久,降低过spring boot版本,替换报错jar与依赖包,更换maven版本、仓库,事实都是无用

  • 这种问题可能是你的spring.datasource driverClassName等信息没有配置

    	spring.datasource.druid.read.driverClassName = com.mysql.cj.jdbc.Driver
    	spring.datasource.druid.read.url=jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&allowMultiQueries=true&serverTimezone=GMT%2B8
    	spring.datasource.druid.read.username=root
    	spring.datasource.druid.read.password=123456
    
  • 还可能是你的jdbc依赖问题,是否有添加:

      	<dependency>  
      		<groupId>org.springframework.boot</groupId>  
      		<artifactId>spring-boot-starter-jdbc</artifactId>  
      	</dependency>  
    
### 解决 Spring Boot 创建 `rabbitAdmin` Bean 失败的问题 当遇到错误提示 "Error creating bean with name 'rabbitAdmin'" 时,通常意味着在初始化 RabbitMQ 的管理组件过程中出现了异常。这类问题的原因多种多样,常见的原因包括但不限于配置文件中的连接参数设置不当、依赖库缺失或版本冲突。 #### 配置检查 确保 application.properties 或 application.yml 文件中包含了正确的 RabbitMQ 连接信息: ```yaml spring.rabbitmq.host=localhost spring.rabbitmq.port=5672 spring.rabbitmq.username=guest spring.rabbitmq.password=guest ``` 如果使用的是自定义的配置类来创建 `RabbitAdmin` 实例,则需确认该类是否正确实现了必要的逻辑[^1]。 #### 依赖验证 对于因缺少必要依赖而导致的 NoClassDefFoundError 类型的错误,应仔细核对 pom.xml (Maven) 或 build.gradle (Gradle),保证引入了所有必需的支持包。特别是针对 Redis 和 GSON 库引发的相关案例表明,某些第三方客户端工具集可能需要额外声明其对应的 Java API 接口实现[^2][^3]。 例如,在 Maven 中添加如下依赖可以解决部分由 Jedis 引起的问题: ```xml <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>${jedis.version}</version> </dependency> ``` 而对于 GSON 版本冲突的情况,可以通过排除默认加载路径下的特定模块并指定兼容版本的方式来处理: ```java @SpringBootApplication(exclude = {GsonAutoConfiguration.class}) public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } ``` 不过需要注意的是,上述措施仅作为一般指导原则;具体到 `rabbitAdmin` Bean 初始化失败的情形下,还需要进一步排查具体的堆栈跟踪日志以定位确切根源所在。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王子様~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值