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

时间:2014-11-10 04:28:34

标签: java postgresql connection

我使用spring-boot连接postgresql数据库。

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

我的application.properties:

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的dbcp BasicDataSource

postgresql.conf中:

listen_addresses = 'localhost'

的pg_hba.conf:

host    all             all             127.0.0.1/32            sha256

因为我只从localhost连接db,所以我认为配置没问题。

但是我得到了以下连接被拒绝的例外。

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 个答案:

没有答案