Spring AOP dot pointer using declared return type

I have the following class and methods:

public class Hello {
    public String getGreetingA() {
        return "hello";
    }
    public boolean getGreetingB() {
        return false;
    }
}

And the next aspect:

@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;
    }
}

Advice is currently being implemented for class methods Hello. I want the aspect to have only target methods that return a type String. It seems that the pointcut executionis not so important here (since the advice is of type Aroundand the return value does not yet exist when the advice is executed).

Is there just why in Spring AOP define a pointcut for targeting Joinpoints that their declared return value is of a particular type?

(I know that I can get the return value pjp.proceedand check it instance of, but I would like to refrain from this)

+4
1

, , getGreetingA, ,

, :

 @Pointcut("execution (public String Hello.*(..))")
 @Around("pointcut()")
0

Source: https://habr.com/ru/post/1676232/


All Articles