postgresql - Spring Boot 无法使用 PostgreSQL 驱动程序加载 DataSource

标签 postgresql spring-data-jpa spring-jdbc spring-boot

我已经使用 Spring Boot 1.0.2.RELEASE(直到今天是 1.0.1.RELEASE)成功开发了一个原型(prototype)。

我搜索了又搜索并尝试了以下解决方案: Spring Boot jdbc datasource autoconfiguration fails on standalone tomcat Spring Boot / Spring Data import.sql doesn't run Spring-Boot-1.0.0.RC1

他们都建议让 Spring Boot 来完成这项工作。 使用 H2 时,一切正常,但是当我尝试切换到 PostgreSQL 时,我得到:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.entityManagerFactory(org.springframework.orm.jpa.JpaVendorAdapter)] threw exception; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.sql.DataSource] is defined

我的build.gradle如下:

loadConfiguration()

def loadConfiguration() {
def environment = hasProperty('env') ? env : 'dev'
project.ext.envrionment = environment
println "Environment is set to $environment"

def configFile = file('config.groovy')
def config = new ConfigSlurper("$environment").parse(configFile.toURL())
project.ext.config = config
}

buildscript {
ext {
    springBootVersion = '1.0.2.RELEASE'
}
repositories {
    mavenCentral()
}
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-   plugin:${springBootVersion}")
}
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'
apply plugin: 'groovy'

war {
baseName = 'test'
version =  '0.0.1-SNAPSHOT'
}

configurations {
providedRuntime
}

repositories {
mavenCentral()
}

dependencies {
compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
compile("org.springframework.boot:spring-boot-starter-thymeleaf:${springBootVersion}")

compile("org.springframework.boot:spring-boot-starter-jdbc:${springBootVersion}")
compile("org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}")
compile("postgresql:postgresql:9.1-901.jdbc4")
//compile("com.h2database:h2")

testCompile("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")

}

task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}

应用程序属性:

spring.jpa.database=POSTGRESQL
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=update

spring.database.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost/cms
spring.datasource.username=cms
spring.datasource.password=NA

删除 application.properties 并将依赖项更改回 H2,一切正常。

我找不到哪里做错了:-(

最佳答案

这是从哪里来的:database.driverClassName=org.postgresql.Driver?你不是说 spring.datasource.driverClassName 吗?

关于postgresql - Spring Boot 无法使用 PostgreSQL 驱动程序加载 DataSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23287462/

相关文章:

sql - Postgresql GROUP_CONCAT 等效?

python - Django 模型不会保存到 Celery Task 中的数据库中

postgresql - Postgres 使用 debezium 创建复制槽失败

mysql - findById 和类似方法在 Spring 中如何工作?

tomcat - 在嵌入式 Tomcat 中使用 Guice?

arrays - 如果安装了 intarray 扩展,Postgres 不会在整数数组上使用索引

java - 如何使用 @ElementCollection 映射子 Set<UUID>

java - 在 spring data jpa 投影中使用嵌入值对象

java - 我们如何修复“java.sql.SQLSyntaxErrorException :

java - 如何在 Spring Boot 中通过 jdbcTemplate 将单个事务与多个数据源一起使用?