簡體   English   中英

Spring Boot無法將Spring Boot連接到PostgreSQL數據庫

[英]spring boot cant connect spring boot to postgresql database

我正在嘗試將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

我正在將PostgreSQL 10與pgAdmin 3 LTS一起使用

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM