小马哥,为什么我在 @Before 和 @Around 里抛出异常都不会触发@AfterThrowing
@Aspect
@Order
public class AspectConfiguration {
@Pointcut("execution(public * *(..))")
private void anyPublicMethod() {
System.out.println("@Pointcut any public method.");
}
@Around("anyPublicMethod()")
public Object aroundAnyPublicMethod(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("@Around any public method");
return pjp.proceed();
}
@Before("anyPublicMethod()")
public void beforeAnyPublicMethod() throws Throwable {
Random random = new Random();
if (random.nextBoolean() || random.nextBoolean()) {
throw new RuntimeException("For purpose");
}
System.out.println("@Before any public method");
}
@After("anyPublicMethod()")
public void finalizeAnyPublicMethod() {
System.out.println("@After any public method");
}
@AfterReturning("anyPublicMethod()")
public void afterAnyPublicMethod() {
System.out.println("@AfterReturning any public method");
}
@AfterThrowing("anyPublicMethod()")
public void afterThrowingAnyPublicMethod() {
System.out.println("@AfterThrowing any public method");
}
}