pgAdmin能連接PostgreSQL,但是網站不能之解決

  • 網站是在spring mvc框架下寫的,從服務器上訪問服務器localhost:5432的數據庫沒有問題,但是同樣的程序想在我的電腦上連自己電腦的數據庫的時候就不行,報錯。
    這個錯誤到處都能查得到:

Request processing failed; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Cannot create PoolableConnectionFactory (Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.)

  • 但是網上都是說讓你查看pg_hba.conf和postgresql.conf,看看訪問權限和監聽地址設置對了沒有。雖然連Localhost是不需要設置的,但我還是把可能的組合試遍了。奇怪的是pgadmin和psql就完全沒有問題。。。後來又發現Navicat可以,IntelliJ IDEA自帶的連接功能不行。
    PowerShell看了一下端口,5432確實在監聽,PID也是postgres,但是這裏的地址寫的是[::1]:5432
    於是把dataSource中的jdbc.url從localhost改成[::1],就神奇地好了。本來還想把系統的默認localhost改成127.0.0.1,看來也不用了。

真的奇怪。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章