org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction
nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory
(Communications link failure
The last packet successfully received from the server was 1,448,137,121,061 milliseconds ago.
The last packet sent successfully to the server was 0 milliseconds ago.)
Caused by: java.net.ConnectException: Connection refused: connect
異常鏈清晰指向:應用無法建立到 MySQL 數據庫的 TCP 連接。Connection refused 表示目標端口無監聽進程或被防火牆攔截。
# Linux
systemctl status mysqld
# 或
service mysql status
# Windows
sc query mysql
netstat -an | grep 3306
ss -lntp | grep 3306
若無輸出,檢查 my.cnf 中 port=3306 及 bind-address 設置。
telnet <db_host> 3306
nc -zv <db_host> 3306
若失敗,檢查安全組、防火牆、iptables 規則。
lsof -i :3306
確認無其他進程佔用 3306 端口。
maxActive/maxTotal 是否過小導致連接耗盡validationQuery 設置(建議 SELECT 1)testOnBorrow 避免無效連接max_connections 是否過小wait_timeout/interactive_timeout 導致長連接被斷開/var/log/mysqld.log 查找異常firewall-cmd --add-port=3306/tcp --permanentmaxTotal、設置 minEvictableIdleTimeMillisautoReconnect=true&failOverReadOnly=false生產環境建議遷移至 HikariCP 連接池,並配置健康檢查機制;監控連接池指標(active/idle/usage),設置告警閾值。