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

使用spring 連接數據庫時,在升級spring boot版本之後,啓動項目報錯如下:


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

    Property: spring.datasource.driverclassname
    Value: org.postgresql.Driver    
    Origin: class path resource [application-postgres.properties]:7:35
    Reason: Failed to load driver class org.postgresql.Driver     in either of HikariConfig class loader or Thread context classloader

在property文件裏面對數據庫的定義如下:

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

數據庫DataSource bean的定義如下:


@Configuration
@Profile("postgres")
public class SourceDataSourceConfigurationLocal {
    @Bean
    @ConfigurationProperties("spring.datasource")
    public DataSource sourceDataSource() {
        return DataSourceBuilder.create().build();
    }

}

解決辦法:

將properties文件當中的

spring.datasource.driverClassName=org.postgresql.Driver  

去掉之後,問題消失

 

 

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章