有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

当我使用java连接postgresql时,连接被拒绝

我使用SpringBoot连接postgresql数据库

我使用postgresql数据库在同一台机器上运行java应用程序

我的申请书。特性:

spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/dbname
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.username=user
spring.datasource.password=passwd

我使用JdbcTemplate和apache的dbcpBasicDataSource

postgresql。形态:

listen_addresses = 'localhost'

pg_hba。形态:

host    all             all             127.0.0.1/32            sha256

因为我只从localhost连接数据库,所以我认为配置是可以的

但我得到了以下例外

Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.)
Caused by: org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Caused by: java.net.ConnectException: Connection refused

我怎样才能解决这个问题


共 (0) 个答案