Spring Boot:无法初始化 PostgreSQL 数据源



我配置了以下 bean。

@Bean
@Primary
@ConfigurationProperties(prefix="datasource.etlTarget")
public DataSource datasourceTest() {
    System.out.println("************");
    System.out.println("************");
    return DataSourceBuilder.create().build();
}

然后错误日志是:

************
************
2014-12-14 21:12:35.718  WARN 21758 --- [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.util.Collection org.springframework.batch.core.configuration.annotation.AbstractBatchConfiguration.dataSources; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'datasourceTest' defined in class path resource [com/testcom/etc/ETLJobRepository.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'datasourceTest' threw exception; nested exception is java.lang.IllegalStateException: No supported DataSource type found
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)

关键错误消息是

nested exception is java.lang.IllegalStateException: No supported DataSource type found

分级设置为

dependencies {
    compile "org.springframework.boot:spring-boot-starter-batch:1.2.0.RELEASE"
    compile "org.springframework:spring-jdbc:4.1.3.RELEASE"
    compile 'org.postgresql:postgresql:9.3-1102-jdbc41'
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

我努力弄清楚为什么它会出错,但没有找出根本原因

该物业是

datasource.etlTarget.url=jdbc:postgresql://localhost/example
datasource.etlTarget.driverClassNname=org.postgresql.Driver
datasource.etlTarget.username=postgres
datasource.etlTarget.password=test

您在配置中输入了拼写错误:

datasource.etlTarget.driverClassNname=org.postgresql.Driver

应该是:

datasource.etlTarget.driverClassName=org.postgresql.Driver

(即 driverClassName而不是driverClassNname

最新更新