java - spring boot 无法将 spring boot 连接到 postgresql 数据库

标签 java postgresql spring-boot postgresql-10

我尝试将 Spring Boot 后端连接到 PostgreSQL,但收到此错误

***************************
APPLICATION FAILED TO START
***************************
Description:

Parameter 0 of constructor in 
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration 
required a bean of type 'javax.sql.DataSource' that could not be found.
- Bean method 'dataSource' not loaded because @ConditionalOnProperty 
(spring.datasource.jndi-name) did not find property 'jndi-name'
- Bean method 'dataSource' not loaded because @ConditionalOnBean (types: 
org.springframework.boot.jta.XADataSourceWrapper; SearchStrategy: all) did 
not find any beans


Action:

Consider revisiting the conditions above or defining a bean of type 
'javax.sql.DataSource' in your configuration.

到目前为止,我已经为这个错误苦苦挣扎了两天

我的 pom.xml 中有这些依赖项

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.4-1206-jdbc42</version>
    </dependency>

这是我的 application.yml

spring:
 jpa:
  database: POSTGRESQL
  show-sql: true
  hibernate:
    ddl-auto: create-drop
 datasource:
  platform: postgres
  url: jdbc:postgresql://localhost:5432/H4E
  username: postgres
  password: 123456

我正在使用带有 pgAdmin 3 LTS 的 PostgreSQL 10

最佳答案

spring.datasource下添加driverClassName属性。你应该得到这样的东西

spring:
    jpa:
        database: POSTGRESQL
        show-sql: true
        hibernate:
            ddl-auto: create-drop
    datasource:
        platform: postgres
        url: "jdbc:postgresql://localhost:5432/H4E"
        username: postgres
        password: 123456
        driverClassName: org.postgresql.Driver

关于java - spring boot 无法将 spring boot 连接到 postgresql 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49036141/

相关文章:

java - 为什么使用 Spring 3.1 WebMvcConfig 进行单元测试会失败?

sql - 当我使用 CASE 将字段设置为 NULL 时,为什么 PostgreSQL 会提示类型?

Django 1.11 PostgreSQL - 每个 session 上的 "SET TIME ZONE"命令

java - ClassNotFoundException : org. springframework.boot.autoconfigure.security.oauth2.resource.OAuth2ResourceServerConfiguration

java - 如何原子运行 2 SQL "SELECT"s?或者在我处理它们之前获取行数的任何其他更好的方法

javascript - GWT CellTable : Selecting one checkbox selects every checkbox/row in the table

java - 将各种类型的对象添加到数组列表中

postgresql - postgresql 物化 View 刷新

java - @Repository count 查询 - 方法executeUpdate 不能用于查询

spring - 使用 spring boot 配置多个 servletcontainers/servlet