1、例如我在SpringBoot項目中使用了阿里的數據庫鏈接池Driud。
有次在啓動的時候,會報這樣的錯:mysql
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure The last packet successfully received from the server was 319 milliseconds ago. The last packet sent successfully to the server was 319 milliseconds ago.
就是數據庫鏈接失敗的問題。spring
爲何會出現這樣的一個問題呢?
出現這樣的一個問題,首先肯定是否是數據庫問題,看看數據庫能不能連上。
若是你的同事或者其餘人都可以連上,那麼數據庫就沒有問題。
看看你能不能上網。
若是你能上網,你的網絡還OK。sql
若是你使用了代理,就是哪一種能幫助你上谷歌的軟件。
你將它關掉,看看問題是否解決了。數據庫
#下面這兩個配置,能夠在每次鏈接的時候判斷一些鏈接是否有效 spring.datasource.druid.test-on-borrow=true spring.datasource.druid.test-while-idle=true