spring boot无法连接spring boot到postgresql数据库

问题描述 投票:0回答:1

我试图将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.

直到这一刻,我一直在努力解决这个错误2天

我在我的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

java postgresql spring-boot postgresql-10
1个回答
1
投票

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

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
© www.soinside.com 2019 - 2024. All rights reserved.