【问题标题】:PostgreSQL hibernate and springPostgreSQL 休眠和春季
【发布时间】:2018-03-19 14:47:20
【问题描述】:

我正在尝试将 Hibernate 与 Spring 和 PostgreSQL 一起使用,但我遇到了很多错误,例如:

org.postgresql.Driver   : Connection error 
ERROR 3424 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool initialization.

我已将 postgreSQL.Driver 放入我的库中,但无事可做,错误提示。

编辑:

2018-03-19 15:54:53.660  INFO 7640 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2018-03-19 15:54:54.664  WARN 7640 --- [           main] unknown.jul.logger                       : ConnectException occurred while connecting to localhost:5432`
`at com.ttmik.back.MainKt.main(main.kt:19) ~[classes/:na]
2018-03-19 15:54:54.675 ERROR 7640 --- [           main] org.postgresql.Driver                    : Connection error:

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.

【问题讨论】:

  • 请添加异常的完整堆栈跟踪以及您的 HikariCP 配置。
  • 我添加了我的错误
  • 您不应该在记录实际 Postgres 错误消息的行之前截断日志
  • 我认为端口号有错误...
  • PostgreSQL 要么不在本地主机上监听,要么至少不在端口 5432 上,要么被防火墙阻止。

标签: spring postgresql hibernate jdbc


【解决方案1】:

检查是否可以使用 telnet 访问您的 PostgreSQL。如果你得到类似的东西:

telnet localhost 5432
Connecting To localhost... 
Could not open connection to the host, on port 5432: Connection failed

那么很可能需要根据this answer on serverfaultpostgresql.conf 文件中的listen_addresses 更改为*

【讨论】: