在搭建微服务项目时出现报错小记,在搭建微服务项目时出现报错小记
报错如图java.lang.Object.wait(Native Method) java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144) com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:41) 2019-06-05 21:49:25.087 INFO 4772 --- [ main] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2019-06-05 21:49:25.089 ERROR 4772 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource: Property: driverclassname Value: com.mysql.cj.jdbc.Driver Origin: "driverClassName" from property source "source" Reason: Failed to load driver class com.mysql.cj.jdbc.Driver in either of HikariConfig class loader or Thread context classloader Action: Update your application's Configuration ,我来为大家科普一下关于在搭建微服务项目时出现报错小记,在搭建微服务项目时出现报错小记?下面希望有你要的答案,我们一起来看看吧!
在搭建微服务项目时出现报错小记,在搭建微服务项目时出现报错小记
报错如图
java.lang.Object.wait(Native Method) java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144) com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:41) 2019-06-05 21:49:25.087 INFO 4772 --- [ main] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2019-06-05 21:49:25.089 ERROR 4772 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource: Property: driverclassname Value: com.mysql.cj.jdbc.Driver Origin: "driverClassName" from property source "source" Reason: Failed to load driver class com.mysql.cj.jdbc.Driver in either of HikariConfig class loader or Thread context classloader Action: Update your application's Configuration
原因:spring boot 会默认加载
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration 这个类
DataSourceAutoConfiguration类使用了@Configuration注解向spring注入了dataSource bean。因为工程中没有关于dataSource相关的配置信息,当spring创建dataSource bean因缺少相关的信息就会报错。
解决办法发是:
在Application类上增加
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
2.出现:
Consider renaming one of the beans or enabling overriding by setting Description: The bean 'dataSource', defined in BeanDefinition defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class] and overriding is disabled. Action: Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
解决办法:在application.yml中添加
main: allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册
如下:
server: port: 8081 spring: application: name: item-service datasource: url: jdbc:mysql://localhost:3306/abc?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai username: root password: root main: allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册 hikari: maximum-pool-size: 30 minimum-idle: 10 eureka: client: service-url: defaultZone: http://127.0.0.1:10086/eureka instance: lease-renewal-interval-in-seconds: 5 # 每隔5秒发送一次心跳 lease-expiration-duration-in-seconds: 10 # 10秒不发送就过期 prefer-ip-address: true ip-address: 127.0.0.1 instance-id: ${spring.application.name}:${server.port}
,免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com