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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With