问题概要
Springboot项目动态注册数据源,当注册数据源为Oracle的时候,初始化HikariDataSource时,报PoolInitializationException: Failed to initialize pool: Timer already cancelled....
。项目使用jaeger 用来链路追踪。
项目配置
springboot version
:2.3.11
opentracing-spring-jaeger-cloud-starter version
: 3.3.1
ojdbc8 version
:19.3.0.0
原因分析
由于项目使用jaeger作为链路追踪,且采用的版本为3.3.1
。在该版本中,使用的contrib-java-jdbc版本为0.2.8
。
在该jaeger版本中,使用的interceptor mode
,需要TracingDriver
第一个注册驱动,以至于该模式可以获取所有jdbc url,在委托给真实的驱动器。但是DriverManager
并没有提供注册顺序,所以该版本便将所有的驱动器先取消注册,然后注册TracingDriver
,在然后将之前取消注册的驱动器,在注册上去。但是Oracle的驱动器并不支持取消注册后在注册。所以会报该错误。
该问题已在contrib-java-jdbc:0.2.11
版本中修复。
Because interceptor mode need TracingDriver be the first driver, so it can accepts any jdbc url then delegate to the real driver, It's a pity that DriverManager doesn't provide a mechanism to control drivers order.
解决方案
升级contrib-java-jdbc版本,将其修改为0.2.11
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-jdbc</artifactId>
<version>0.2.11</version>
</dependency>
</dependencies>
</dependencyManagement>