繁体   English   中英

无法连接 Spring 启动到远程 PostgreSQL 服务器

[英]Cannot connect Spring Boot to remote PostgreSQL server

我正在尝试将我的 Spring Boot 应用程序连接到远程 PostgreSQL 服务器数据库。

我的 application.properties 文件具有以下内容:

server.port=8102
spring.jpa.database=POSTGRESQL
spring.datasource.platform=postgres
spring.datasource.url=jdbc:postgresql:192.168.4.33:5432/postgres
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.username=postgres
spring.datasource.password=secretpassword
spring.jpa.show-sql=true
logging.level.org.springframework.web=debug
logging.level.org.hibernate=debug
spring.jpa.generate-ddl=true

但是,当我尝试运行我的应用程序时,出现以下错误:

org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

我不确定为什么 Spring Boot 仍在尝试使用本地主机,因为我确定我已经明确要求它改用 IP 地址。

你有连接拒绝。请确保你的数据库和正确的用户名和 pass.or.network 是好的。

jdbc:postgresql://HOST:PORT/activitydb

确保 URL 是正确的。

spring.datasource.url=jdbc:postgresql:192.168.4.33:5432/postgres

你应该使用spring.datasource.url=jdbc:postgresql://192.168.4.33:5432/postgres

如果它不起作用,那么我建议查看您的防火墙或检查该端口是否在服务器上打开。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM