274 字
1 分钟
spring boot之配置数据源时提示无法加载驱动类
参考链接
[](https://stackoverflow.com/questions/6202653/difference-between-oracle-jdbc-driver-classes/6202721#6202721)[Difference between Oracle jdbc driver classes?](https://stackoverflow.com/questions/6202653/difference-between-oracle-jdbc-driver-classes/6202721#6202721)[——stackoverflow@bw_üezi](https://stackoverflow.com/questions/6202653/difference-between-oracle-jdbc-driver-classes/6202721#6202721)spring boot之配置数据源时提示spring boot Cannot load driver class: oracle.jdbc.driver.OracleDriver
1. 环境的maven是自定义了本地仓库位置,但是idea配置maven的设置时却引用的C:\Users\Administrator\.m2\repository,如果自定义了,iDea中也一定要配置好。 2. Idea设置问题,由于我环境的maven是自定义了本地仓库位置,但是idea配置maven的设置时却引用的C:\Users\Administrator\.m2\repository,如果自定义了,iDea中也一定要配置好。
- oracle9i开始就不允许使用_oracle.jdbc.driver.OracleDriver_驱动名,而需要使用oracle.jdbc.OracleDriver
- 没有初始化相应的bean,或者没有使用注解@Bean使用于相关数源方法,以下我是之前错误的代码
@ConfigurationProperties("oracle.datasource")public DataSourceProperties oracleDataSourceProperties(){ return new DataSourceProperties();}@Beanpublic DataSource oracleDataSource() { DataSourceProperties dataSourceProperties =oracleDataSourceProperties(); System.out.println("oracle.datasource: {}"+dataSourceProperties.getUrl()); return dataSourceProperties.initializeDataSourceBuilder().build();}@Bean@Resourcepublic PlatformTransactionManager oracleTxManager(DataSource oracleDataSource) { return new DataSourceTransactionManager(oracleDataSource);}以上如果仔细看,可以看到oracleDataSourceProperties()这个方法没有使用注解@Bean,导致其一个bean在初始时找不到,我在打印输出时提示“oracle.datasource: {}null”
spring boot之配置数据源时提示无法加载驱动类
https://iszengmh.pages.dev/posts/spring-boot之配置数据源时提示无法加载驱动类/