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()")
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>