Spring引导无法使用PostgreSQL驱动程序加载数据源

Spring引导无法使用PostgreSQL驱动程序加载数据源,postgresql,spring-data-jpa,spring-jdbc,spring-boot,Postgresql,Spring Data Jpa,Spring Jdbc,Spring Boot,我已经成功地使用SpringBoot 1.0.2.RELEASE(直到今天之前是1.0.1.RELEASE)开发了一个原型 我搜索了又搜索,尝试了以下解决方案: 他们都建议让Spring Boot来完成这项工作。 使用H2时,一切正常,但当我尝试切换到PostgreSQL时,我得到: Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityM

我已经成功地使用SpringBoot 1.0.2.RELEASE(直到今天之前是1.0.1.RELEASE)开发了一个原型

我搜索了又搜索,尝试了以下解决方案:

他们都建议让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'
}
application.properties:

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,一切正常


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

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

如果依赖项没有刷新,试着重新导入你的mvn项目,还要在你的
pom.xml

 <dependency>
            <groupId>postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.1-901.jdbc4</version>
</dependency>

我在我的
构建中有这个。gradle

实现“org.postgresql:postgresql:version number”

但是,无论我做了什么,jar都没有被下载

作为解决方法,我从下载了jar(单击
jar(…)
),并手动将其添加到我的Java构建路径库中。 不理想,但这是2分钟内唯一有效的方法

spring.datasource.driver-class-name=org.postgresql.Driver

如果您最近刚刚将Postgre添加到依赖项中,请确保重新加载您的项目。

绝对正确。复制粘贴拼写错误!问题已更新。谢谢!多大的拼写错误!好的,数据源而不是数据库!他有一个gradle项目!您可以尝试此网站将maven转换为gradle
spring.datasource.driver-class-name=org.postgresql.Driver