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>  
    
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

王子様~

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

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

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

打赏作者

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

抵扣说明:

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

余额充值