org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection 异常

it2025-12-12  10

记录以防再次遇到。网上有很多遇到相同问题,但原因不一样的,所以解决方案不一样,仅记录其中一种问题。

我遇到的现象:正常访问数据库没问题,加上@Transactional注解后调用该方法抛出以下异常(无法进入方法,断点无效)。

org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.     at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:308)     at org.springframework.transaction.support.AbstractPlatformTransactionManager.startTransaction(AbstractPlatformTransactionManager.java:400)

解决方案:系统中配置了三个数据库,三个数据源,但其中两个数据库未启动(目前做的部分不用,就没启动)。启动以后问题解决。

最新回复(0)