亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用Docker橋接網絡時無法在集成測試中獲取JDBC連接

使用Docker橋接網絡時無法在集成測試中獲取JDBC連接

守候你守候我 2021-05-01 16:57:25
當我在maven test本地運行時通過。但是,當我在CI服務器上運行該錯誤時,出現此錯誤。Error MessageCould not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC ConnectionStacktraceorg.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC ConnectionCaused by: org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC ConnectionCaused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failureThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.Caused by: java.net.UnknownHostException: mysql運行本地測試時,它們都通過了測試,并使用IntelliJ IDEA提供的maven測試默認設置。由于該錯誤抱怨數據庫連接問題,因此我通過Jenkins Audit檢查了Database Plugin。連接成功!我的連接參數application.properties也與此對應spring.datasource.url=jdbc:mysql://mysql:3306/database?useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghaispring.datasource.username=rootspring.datasource.password=passwordspring.datasource.maxActive=5URL中的MySQL是MySQL docker容器名稱。如果用錯誤消息中的localhost或專用IP進行更改docker container inspect mysql是相同的,而后兩行中的Stacktrace則有所不同。對于本地主機The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.Caused by: java.net.ConnectException: Connection refused (Connection refused)用于私有IPThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. Caused by: java.net.SocketTimeoutException: connect timed out我認為不同的是URL中的主機,localhost用于本地測試。而Jenkins服務器則使用Docker橋接網絡。總結:1.通過maven的本地測試通過2. Jenkins插件成功連接到MySQL3.從Jenkins運行時,集成測試失敗。4.本地測試環境為WIN10 64bit;Jenkins在Ubuntu 16.04 64位服務器上的docker容器中運行,MySQL 5.7容器連接到同一網橋網絡。
查看完整描述

3 回答

?
牧羊人nacy

TA貢獻1862條經驗 獲得超7個贊

您應該將Docker容器的mysql端口綁定到VM中的端口。

在下面的線程中對此進行了很好的解釋。

值得嘗試...
如何與在Docker中作為容器運行的MySQL DB連接?


查看完整回答
反對 回復 2021-05-12
  • 3 回答
  • 0 關注
  • 530 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號