1. 程式人生 > 其它 >SQLException: Connections could not be acquired from the underlying database!

SQLException: Connections could not be acquired from the underlying database!

問題描述:測試時資料庫連線太久,估計執行不了

果然,提示異常:

SQLException: Connections could not be acquired from the underlying database!

1.這問題應該是資料庫資訊不正確造成的,檢查資料庫資訊

2.因為問題發生在jdbcTemplate注入時,所以先確定資料庫是否有問題。使用上述資料庫資訊,手動連線資料庫確認是否正常。

3.資料庫資訊驗證無誤,那麼肯定是applicationContext.xml裡依賴注入的問題,但是資料庫裡配置的資訊應該沒錯才對。那麼問題就是映射了:applicationContex.xml和db.properties之間通過什麼連線?

<context:property-placeholder location="classpath:db.properties"/>

property-placeholeder匯入,再通過$替換符替換,那麼問題就應該出在這個$的問題上(我給了str1,但你${str1}轉換後沒有給我str1的字串)

4.把db.properties裡的key值都修改,username改為jdbc.username,果然成功了

5.由此確定了,${username}實際上是列印的系統使用者名稱,使用者名稱不正確自然無法進行連線。

後記:這個bug應該和之前一段時間log4j爆出來的漏洞是一個原理的,通過${}可以獲得的不是應出現的字串從而使伺服器實現RMI(遠端呼叫),而遠端呼叫的服務是由黑客控制的,從而使黑客可以遠端控制伺服器。(大概是這樣)