原因:未知
解决方案: 使用编程式事务
@Override
public void run() {
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
PlatformTransactionManager txManager = ContextLoader.getCurrentWebApplicationContext().getBean(PlatformTransactionManager.class);
TransactionStatus status = txManager.getTransaction(def);
try {
testDao.save(entity);
txManager.commit(status); // 提交事务
} catch (Exception e) {
System.out.println("异常信息:" + e.toString());
txManager.rollback(status); // 回滚事务
}
}
本文介绍了一种通过编程方式实现的事务处理方法,该方法利用Spring框架提供的Transaction API来手动控制事务的开启、提交和回滚过程。具体实现中,通过DefaultTransactionDefinition设置事务传播行为,并借助PlatformTransactionManager进行事务管理。
2413

被折叠的 条评论
为什么被折叠?



