[spring error] Failed to bind properties under 'spring.datasource' to javax.sql.DataSource:

àì夳堔傛蜴生んèń 2021-09-29 01:10 450阅读 0赞

使用spring 连接数据库时,在升级spring boot版本之后,启动项目报错如下:

  1. Failed to bind properties under 'spring.datasource' to javax.sql.DataSource:
  2. Property: spring.datasource.driverclassname
  3. Value: org.postgresql.Driver
  4. Origin: class path resource [application-postgres.properties]:7:35
  5. Reason: Failed to load driver class org.postgresql.Driver in either of HikariConfig class loader or Thread context classloader

在property文件里面对数据库的定义如下:

  1. spring.datasource.url=jdbc:postgresql://localhost:5432/test
  2. spring.datasource.username=user
  3. spring.datasource.password=ped
  4. spring.datasource.driverClassName=org.postgresql.Driver

数据库DataSource bean的定义如下:

  1. @Configuration
  2. @Profile("postgres")
  3. public class SourceDataSourceConfigurationLocal {
  4. @Bean
  5. @ConfigurationProperties("spring.datasource")
  6. public DataSource sourceDataSource() {
  7. return DataSourceBuilder.create().build();
  8. }
  9. }

解决办法:

将properties文件当中的

  1. spring.datasource.driverClassName=org.postgresql.Driver

去掉之后,问题消失

发表评论

表情:
评论列表 (有 0 条评论,450人围观)

还没有评论,来说两句吧...

相关阅读