今天新建了一个SpringBoot项目,要连接Oracle数据库,就找之前的旧项目里的jdbc配置方法复制过来,结果启动的时候报警告,如下:
Registered driver with driverClassName=oracle.jdbc.driver.OracleDriver was not found, trying direct instantiation.
虽然说也能正常运行,但是对于强迫症的我来说,还是希望能找到问题并解决掉,万一以后遇到奇奇怪怪的错误,就比较麻烦了。
经过一番查找,是因为application.yml(或者application.properties里的配置数据库连接池的driver-class-name的问题)
spring: datasource: driver-class-name: oracle.jdbc.driver.OracleDriver url: jdbc:oracle:thin:@10.27.58.1:1521:orcl username: someusername password: somepassword
因为driver-class-name是找之前旧项目中复制过来的:oracle.jdbc.driver.OracleDriver
而Oracle官方新版的数据库驱动已经deprecated用新的名字:oracle.jdbc.OracleDriver
pom中我使用的jdbc驱动是ojdbc10:
<!-- https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc10 --> <dependency> <groupId>com.oracle.database.jdbc</groupId> <artifactId>ojdbc10</artifactId> <version>19.13.0.0.1</version> </dependency>
Oracle官方的说法:
For Oracle 9i onwards you should use oracle.jdbc.OracleDriver rather than oracle.jdbc.driver.OracleDriver as Oracle have stated that oracle.jdbc.driver.OracleDriver is deprecated and support for this driver class will be discontinued in the next major release.
已经很久没有使用Oracle了,所以也没有留意什么时候已经换驱动名字了
换个写法,正确的application.properties写法是:
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver spring.datasource.url:jdbc:oracle:thin:@10.27.58.1:1521:orcl spring.datasource.username=someusername spring.datasource.password=somepassword
文章评论