在为我的服务运行集成测试时,我遇到了以下异常:
ERROR o.a.tomcat.jdbc.pool.ConnectionPool: Unable to create initial connections of pool.
Caused By: java.sql.SQLException: Driver:com.mysql.jdbc.Driver@xxxxx returned null for URL:<no value>
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:326)我正在使用org.flywaydb插件,在pom.xml中定义如下:
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<url>jdbc:mysql://localhost:3306/mydb</url>
<user>admin</user>
<password>pwd</password>
<validateOnMigrate>false</validateOnMigrate>
</configuration>
</plugin>在application.yaml中,我将集成测试的属性定义为:
spring:
profiles:integration-tests
datasource:
driverClassName: org.h2.Driver
url: jdbc:h2:mem:mydb;MODE=MySQL;DB_CLOSE_ON_EXIT=FALSE;INIT=RUNSCRIPT FROM 'classpath:/path/schema.sql'
username: root
password:
show_sql: false发布于 2022-04-25 15:12:10
首先需要澄清的是,maven天桥插件和Spring数据源属性在使用时间上没有关系:
process
第二件事
url: jdbc:h2:mem....
url: jdbc:mysql....运行脚本(如果有的话)。这就是为什么flyway会配置另一个数据库,而不是测试中使用的数据库。
第三件事:
SpringBoot似乎没有“查看”数据源属性和/或驱动程序url: <no value>。你是如何进行测试的?你设定了正确的弹簧轮廓吗?
https://stackoverflow.com/questions/71998768
复制相似问题