当前位置: 首页 > 知识库问答 >
问题:

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

严易安
2023-03-14

我已经成功地使用Spring Boot 1.0.2开发了一个原型。发布(直到今天才发布1.0.1版本)。

我已经搜索并尝试了一些解决方案,比如:Spring Boot jdbc数据源自动配置在独立的tomcat Spring Boot/Spring数据导入上失败。sql不运行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

我的身材。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

正在删除应用程序。属性,并将依赖关系更改回H2,一切正常。

我找不到我做错了什么:-(

共有3个答案

舒仲渊
2023-03-14

如果依赖项没有刷新,请尝试重新导入您的mvn项目,并将以下内容添加到您的pom中。xml

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

或者到你的build.gradle

implementation "postgresql:postgresql:9.1-901.jdbc4"
段干宏硕
2023-03-14
spring.datasource.driver-class-name=org.postgresql.Driver

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

勾学博
2023-03-14

这是从哪里来的:数据库。driverClassName=org。postgresql。司机?你不是说Spring吗。数据源。driverClassName?

 类似资料:
  • 应用.yml build.gradle: 错误: 知道我错过了什么吗? 我试图从yml文件中删除:driverClassName: org.h2.Driver。不工作。 尝试将build.gradle和版本修改为H2..也不起作用。

  • 嘿,伙计们,还有一个问题,下面是信息

  • 我正在处理Spring Boot项目,突然遇到应用程序无法加载MySQL jdbc的问题。(我编译了一次这个项目,没有改变任何东西) 这是我的pom.xml: 这是我的application.properties: Logcat: MySQL数据库最初是使用hibernate创建的。这些配置工作正常,但我不确定这里的真正问题是什么 编辑:我删除了。m2文件夹并从一开始安装所有依赖项。

  • 问题内容: 我在春季配置了一个netezza db。我在类路径中添加了依赖的nzjdbc.jar 春季配置: 问题答案: 将放入您的本地Maven存储库 (在该目录执行这个位于 然后像正常依赖项一样使用它: @请参阅安装第三方JAR的指南

  • 我正在尝试将MySQL数据库连接到weblogic,以便我可以在我的项目中使用它,我对此很陌生,无论如何,我已经创建了一个数据源,我选择MySQL作为数据库类型 C:\Oracle\Middleware\wlserver\U 10.3\server\ext\jdbc\mysql 但它不起作用!

  • 这是hibernate.cfg.xml: 这是Hibernate实用程序文件: