user8537525
user8537525

Reputation:

spring aop execution returning type

I intercept methods through AspectJ. And I need in pointcut expression execution(* *.*(..)) add returning type TestObj. How can I do this?

@Around("@annotation(interceptor) && execution(* *.*(..)) && args(argType, ..)")
public Object logAction(ProceedingJoinPoint joinPoint, Interceptor interceptor, TestObj argType) throws Throwable {
    // do smth
}

Upvotes: 2

Views: 1471

Answers (1)

Karol Dowbecki
Karol Dowbecki

Reputation: 44952

The execution() expression supports the return type filtering. If you need the return type to be TestObj, or any of it's subtypes, following should work:

@Around("@annotation(interceptor) && execution(* TestObj *.*(..)) && args(argType, ..)")
public Object logAction(ProceedingJoinPoint joinPoint, Interceptor interceptor, TestObj argType) throws Throwable {

You can find more in the official docs, Chapter 2. Annotations:

execution(public (@Immutable *) org.xyz..*.*(..))

The execution of any public method in a package with prefix org.xyz, where the method returns an immutable result.

Upvotes: 2

Related Questions