为了账号安全,请及时绑定邮箱和手机立即绑定

如何将 Spring Boot Web 应用程序连接到 postgresql 数据库

如何将 Spring Boot Web 应用程序连接到 postgresql 数据库

汪汪一只猫 2022-07-06 10:45:05
我正在开发一个 Spring Boot 项目,并尝试将我的服务器连接到 postgresql 数据库。当我使用我的 IDE(在我的 Windows 操作系统上)运行程序时,它正在工作,但是当我制作一个 jar 文件并在托管我的数据库的 ubuntu 服务器虚拟机上运行它时,它不起作用。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.我检查了我的防火墙规则,但仍然没有成功。Chain INPUT (policy ACCEPT)target     prot opt source               destinationChain FORWARD (policy ACCEPT)target     prot opt source               destinationChain OUTPUT (policy ACCEPT)target     prot opt source               destination我做了一些研究,听说要修改 postgresql 的配置文件,但它仍然不起作用,我不知道问题出在哪里。在我在 postgresql.conf 上修改的行下面:listen_addresses = '*'          # what IP address(es) to listen on;ssl = on对于 pg_hba.conf:local   all             postgres                                peerlocal   all             kapitax                                trust# TYPE  DATABASE        USER            ADDRESS                 METHOD#host   all             kapitax        *                       password#host   all             all             0.0.0.0/0               md5# "local" is for Unix domain socket connections onlylocal   all             all             *                       trust# IPv4 local connections:host    all             all             *                       password# IPv6 local connections:host    all             all             ::1/128                 password# Allow replication connections from localhost, by a user with the# replication privilege.local   replication     all                                     peerhost    replication     all             *                       md5host    replication     all             ::1/128                 md5问题可能来自 applcation.properties 代码?spring.datasource.url= jdbc:postgresql://localhost:5432/kapitaxspring.datasource.username=kapitaxspring.datasource.password=kapitaxspring.jpa.hibernate.ddl-auto=create-dropserver.port=8090
查看完整描述

1 回答

?
慕莱坞森

TA贡献1810条经验 获得超4个赞

线

#host   all             all             0.0.0.0/0               md5

应该像这样启用:

host   all             all             0.0.0.0/0               md5

0.0.0.0/0您一起侦听所有 IPv4 地址。更改此配置后,请确保重新加载服务器设置或重新启动数据库服务器。更详细的解释可以在下面的答案中找到:How to configure PostgreSQL to accept all incoming connections


查看完整回答
反对 回复 2022-07-06
  • 1 回答
  • 0 关注
  • 313 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信