Java 要在方法中使用的方面返回值
Java Aspect returned value to be used in the method
我有一个 @After
java 运行特定逻辑的方面。我需要它 return 一个结果(一个对象),该结果(一个对象)可以在方面的切入点截获的方法中使用。可能吗?
你需要的是@Around
,它允许你return任何你想要的建议对象:
@Around("com.xyz.myapp.UserService.createUser()")
public Object userCreationAdvice(ProceedingJoinPoint pjp) throws Throwable {
//Do something if needed before method execution
Object retVal = pjp.proceed();
//Do something if needed after method execution
return retVal;
}
我有一个 @After
java 运行特定逻辑的方面。我需要它 return 一个结果(一个对象),该结果(一个对象)可以在方面的切入点截获的方法中使用。可能吗?
你需要的是@Around
,它允许你return任何你想要的建议对象:
@Around("com.xyz.myapp.UserService.createUser()")
public Object userCreationAdvice(ProceedingJoinPoint pjp) throws Throwable {
//Do something if needed before method execution
Object retVal = pjp.proceed();
//Do something if needed after method execution
return retVal;
}