Java – spring declares AOP pointcuts for return types
I have the following classes and methods:
public class Hello { public String getGreetingA() { return "hello"; } public boolean getGreetingB() { return false; } }
And the following aspects:
@Aspect public class HelloAspect { @pointcut("execution (public String Hello.*(..)") public void pointcut() {} @Around("pointcut") public Object advice(ProceedingJoinPoint pjp) { // do something... Object result = pjp.proceed; // do something... return result; } }
Currently, the recommendations are implemented for both Hello class methods I want aspects only for methods that return string types It seems that the execution pointcut is irrelevant here (because the proposal is of type around and the return value does not exist when the proposal is executed)
Is there a simple reason to define a pointcut in spring AOP to locate joinpoints whose declared return value is of some type?
(I know I can get the return value of pjp.proceed and check its instance, but I want to avoid doing so)
Solution
I have copied your course. As expected, this aspect is only applicable to getgreening A. I can't reproduce your situation. Both are targeted
There are some syntax errors in your example. Here is the correct code:
@pointcut("execution (public String Hello.*(..))") @Around("pointcut()")