public void addTransaction(Transaction transaction){
}
@AfterThrowing(execution="(..)")
我正在执行一个事务,我想抛出一个异常并在 AOP @AfterThrowing
方法中捕获它。我想访问在我的方法中传递的对象并在 @AfterThrowing
方法
我想在我的 afterthrowing 方法中使用该事务对象。怎么做?
最佳答案
您可能需要一个周围的建议,例如:
@Aspect
@Component
public class ExceptionAspect {
@Around("@annotation(hello.LogException")
public Object handelLogging(ProceedingJoinPoint joinPoint) throws Throwable {
try {
return joinPoint.proceed();
}
catch (Exception e) {
// based on the exception that will cause a transaction rollback call your method here
throw e;
}
}
}
不确定为什么需要该交易,请查看 this answer获取当前交易的帮助。
另请参阅hibernate interceptors其中有 afterTransactionCompletion method
关于java - 如何在Spring Boot中的@AfterThrowing方法中访问对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49277138/