造成这个异常的原因是在方法上加了事务标签@Transactional,这个标签,默认的超时时间是5秒钟,如果这个方法执行的时间超过了5秒,就会报这个异常。
org.springframework.transaction.UnexpectedRollbackException: JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is javax.transaction.RollbackException: One or more resources refused to commit (possibly because of a timeout in the resource - see the log for details). This transaction has been rolled back instead.
可以手动设置超时时间,
@Transactional(propagation=Propagation.REQUIRED,timeout=5)
我还在网上看到另外一个说法