Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring AOP: Getting return types in after-returning method

I was trying to implement after-returning in Spring AOP and the basic implementation works fine:

public void afterExecution(JoinPoint jp){
    System.out.println("Returning");
    System.out.println("Returning from: " + jp.toString());
            // How to get the return type object here?
}

How to get the return type object in the above method?

This is what I added in the context xml file:

<aop:pointcut id="emplRet" expression="execution(java.lang.String com.model.Employee.get*())"/>
    <aop:aspect ref="aspect">
        <aop:after-returning pointcut-ref="emplRet" method="afterExecution"/>
    </aop:aspect>

Please advice.

like image 514
user182944 Avatar asked Jun 11 '26 09:06

user182944


1 Answers

You can specify

returning="retVal"

in your pointcut expression and add a parameter to your method. You would have to reference the bound value retVal in your after-returning advice.

Spring AOP documentation.

like image 173
Sotirios Delimanolis Avatar answered Jun 12 '26 22:06

Sotirios Delimanolis