引起的原因:org.postgresql.util.PSQLException:与 localhost:5432 的连接被拒绝。检查主机名和端口是否正确以及邮局主管是否接受 TCP/IP 连接。
我在创建 docker 镜像时遇到问题。
当我检查 postgres 端口时
postgres 4318 iqbal 8u IPv4 0xbccc4b164eb6b423 0t0 TCP 127.0.0.1:5432 (LISTEN)
com.docke 11144 iqbal 45u IPv6 0xbccc4b1b1bb15e0b 0t0 TCP *:5432 (LISTEN)
Run Code Online (Sandbox Code Playgroud)
应用程序.properties 文件
spring.mvc.converters.preferred-json-mapper=gson
spring.datasource.url= jdbc:postgresql://localhost:5432/flightbed
spring.datasource.username= iqbal
spring.datasource.password= postgres
spring.datasource.hikari.connectionTimeout=20000
spring.datasource.hikari.maximumPoolSize=5
spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.hibernate.ddl-auto= update
spring.jpa.show-sql=true
Run Code Online (Sandbox Code Playgroud)
Docker-compose 文件在这里:
version: '3.1'
services:
app:
image: 'docker-spring-boot-postgres:latest'
build:
context: .
container_name: app
depends_on:
- localhost
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://postgresqldb:5432/flightbed
- SPRING_DATASOURCE_USERNAME=iqbal
- SPRING_DATASOURCE_PASSWORD=postgres
- SPRING_JPA_HIBERNATE_DDL_AUTO=update
localhost:
image: 'postgres:13.1-alpine'
container_name: postgresqldb
environment:
- …Run Code Online (Sandbox Code Playgroud)