【发布时间】:2021-10-21 07:53:19
【问题描述】:
我正在尝试设置 Spring Boot 应用程序。目前我在本地环境中工作,我有一个 Heroku PostgreSQL 数据库。当我启动我的应用程序时,它以错误开头:
HikariPool-1 - Exception during pool initialization.
org.postgresql.util.PSQLException: El intento de conexión falló.
...
Caused by: java.net.UnknownHostException: @host
...
HHH000342: Could not obtain connection to query metadata
为了安全起见,我添加了正确的主机名并将其隐藏。我知道这个主机名是正确的,因为我已经设法使用 Express 应用程序进行连接。
我的 POM.xml 有以下依赖项:}
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
而我的 application.properties 文件是:
spring.datasource.url=jdbc:postgresql://@host:5432/dal2fiqv9or5eg?user=----&password=----&sslmode=require
spring.datasource.username=----
spring.datasource.password=----
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa-hibernate.ddl-auto=create-drop
spring.jpa.show=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.format_sql=true
我再次隐藏了主机、用户名和密码。
在此之后应用程序启动。
【问题讨论】:
标签: postgresql spring-boot spring-data-jpa heroku-postgres