當(dāng)我在maven test本地運(yùn)行時通過。但是,當(dāng)我在CI服務(wù)器上運(yùn)行該錯誤時,出現(xiàn)此錯誤。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運(yùn)行本地測試時,它們都通過了測試,并使用IntelliJ IDEA提供的maven測試默認(rèn)設(shè)置。由于該錯誤抱怨數(shù)據(jù)庫連接問題,因此我通過Jenkins Audit檢查了Database Plugin。連接成功!我的連接參數(shù)application.properties也與此對應(yīng)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或?qū)S肐P進(jìn)行更改docker container inspect mysql是相同的,而后兩行中的Stacktrace則有所不同。對于本地主機(jī)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我認(rèn)為不同的是URL中的主機(jī),localhost用于本地測試。而Jenkins服務(wù)器則使用Docker橋接網(wǎng)絡(luò)??偨Y(jié):1.通過maven的本地測試通過2. Jenkins插件成功連接到MySQL3.從Jenkins運(yùn)行時,集成測試失敗。4.本地測試環(huán)境為WIN10 64bit;Jenkins在Ubuntu 16.04 64位服務(wù)器上的docker容器中運(yùn)行,MySQL 5.7容器連接到同一網(wǎng)橋網(wǎng)絡(luò)。
3 回答

牧羊人nacy
TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超7個贊
您應(yīng)該將Docker容器的mysql端口綁定到VM中的端口。
在下面的線程中對此進(jìn)行了很好的解釋。
值得嘗試...
如何與在Docker中作為容器運(yùn)行的MySQL DB連接?
添加回答
舉報
0/150
提交
取消