微服务项目排错: DruidDataSourceAutoConfigure Init DruidDruidDataSource

本文详述了一次在Spring Cloud Alibaba项目中遇到的启动问题,服务在初始化DruidDataSource时卡住并不断打印INFO日志。通过调整日志级别至DEBUG,发现了Bean创建错误,提示无法确定合适的驱动类。分析后判断为MySQL JAR版本冲突。通过Maven的dependency:tree命令定位冲突源,发现在顶级项目的父POM中配置了不同版本的mysql-connector-java。最终,通过修改版本号并重新构建解决了问题。

文章记录项目报错排查过程:

问题描述:项目架构 spring cloud alibaba ,其中一服务启动时一直卡在 Init DruidDataSource,且在不停地打印INFO级别的 " Init DruidDataSource"

 [main] INFO  c.a.d.s.b.a.DruidDataSourceAutoConfigure:56 - Init DruidDataSource
 [main] INFO  c.a.d.s.b.a.DruidDataSourceAutoConfigure:56 - Init DruidDataSource
 [main] INFO  c.a.d.s.b.a.DruidDataSourceAutoConfigure:56 - Init DruidDataSource
 ....

修改logback.xml日志配置文件,修改为DEBUG级别,打印更多详细日志

发现一在个DEBUG级别的日志中隐藏着Bean创建错误如下:

2021-06-08 17:05:18.896 [main] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker:335 - Bean 'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties' of type [org.springframework.boot.autoconfigure.jdbc.DataSourceProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-06-08 17:05:18.913 [main] DEBUG o.s.b.factory.support.DefaultListableBeanFactory:1665 - Bean creation exception on eager FactoryBean type check: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jimuReportShareDao' defined in URL [jar:file:/C:/Users/admin/.m2/repository/org/jeecgframework/jimureport/spring-boot-starter-jimureport/1.3.1-beta4/spring-boot-starter-jimureport-1.3.1-beta4.jar!/org/jeecg/modules/jmreport/desreport/dao/JimuReportShareDao.class]: Cannot create inner bean '(inner bean)#430212cb' of type [org.jeecgframework.minidao.aop.MiniDaoHandler] while setting bean property 'proxy'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '(inner bean)#430212cb#9': Unsatisfied dependency expressed through field 'jdbcTemplate'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jdbcTemplate' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/JdbcTemplateConfiguration.class]: Unsatisfied dependency expressed through method 'jdbcTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [com/alibaba/druid/spring/boot/autoconfigure/DruidDataSourceAutoConfigure.class]: Invocation of init method failed; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class

主要异常堆栈最后一个报错当作根本原因: Failed to determine a suitable driver class

目测应该是Jar冲突,打开IDEA的项目JAR依赖视图
在这里插入图片描述
果然发现有两个版本不同的mysql jar

接下自然就想到用maven 的 dependeny:tree 目标打印依赖关系
打印报错服务的依赖视频后,经验检查并没有发现有8.0.21的包,推测可能是和其它服务或parent项目的依赖有冲突,对顶级项目执行 dependeny:tree

+- org.jeecgframework.boot:jeecg-boot-base-tools:jar:2.4.3:compile
+- mysql:mysql-connector-java:jar:8.0.21:runtime

+- org.springframework.boot:spring-boot-starter-web:jar:2.3.5.RELEASE:compile
+- mysql:mysql-connector-java:jar:8.0.22:runtime

发项顶级项目中配置了:
<mysql-connector-java.version>8.0.21</mysql-connector-java.version>

故修改pom.xml配置的版本号,重新构建,问题解决

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

licbc

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

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

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

打赏作者

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

抵扣说明:

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

余额充值