当我在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
提交
取消