當我在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容器連接到同一網橋網絡。
添加回答
舉報
0/150
提交
取消