You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot连接ElephantSQL托管PostgreSQL数据库报错求助

Spring Boot 连接 ElephantSQL PostgreSQL 托管数据库报错

我正在开发一个基于Spring Boot的简易应用,选用PostgreSQL作为数据存储方案,数据库托管在ElephantSQL平台。目前Spring Boot应用无法正常连接数据库,报错信息为:

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.

已确认信息

  • 已通过pgAdmin4成功连接该ElephantSQL数据库,说明数据库访问权限、网络连接无问题。
  • ElephantSQL提供的数据库连接信息:
    • 数据库地址为ElephantSQL分配的远程地址(非localhost)
    • 数据库名称、用户名、密码均已通过pgAdmin4验证正确
  • Spring Boot application.properties 配置内容:
    spring.datasource.url=jdbc:postgresql://localhost:5432/xxx
    spring.datasource.username=xxx
    spring.datasource.password=xxx
    spring.datasource.driver-class-name=org.postgresql.Driver
    
  • pom.xml 已引入PostgreSQL驱动依赖:
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
    </dependency>
    

恳请各位帮忙排查连接失败的原因,提供解决方案!

内容的提问来源于stack exchange,提问作者Eduardo Lopes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 16:27:02