线程Thread中声明式事务不起作用

原因:未知

解决方案: 使用编程式事务

	@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); // 回滚事务
									}
								
								}

猜你喜欢

转载自blog.csdn.net/rumengqiang/article/details/79917142