@Around("myPointcut()")
public Object aroundExecute(ProceedingJoinPoint p) {
Object res = null;
//XXX 此处还可以添加方法调用的权限功能 或者考虑在Filter中做
//事务的开始
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
TransactionStatus status = txManager.getTransaction(def);
try {
System.out.println("around befroe");
res = p.proceed();
System.out.println("around after");
// System.out.println(res);
} catch (Throwable e) {
logger.error(e.toString());
txManager.rollback(status);//回滚事务
ResultModelMap<Object> resm = new ResultModelMap<Object>(CME.EXCEPTION);
resm.appendMessage(e.getMessage());
resm.setExceptionCause(e.getCause());
return resm;
}
txManager.commit(status);//提交事务
return res;
}
Spring手动编写事务DEMO
最新推荐文章于 2025-05-21 10:02:45 发布