Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the return value by spring aop [closed]

Tags:

I have a method with a return value in DAO layer, I want to change the return value by spring AOP, according different requirement,s and then send to corresponding method in SERVICE layer; but i don't know how to do so.

like image 252
cleverUtd Avatar asked Dec 24 '12 06:12

cleverUtd


1 Answers

You can apply an @Around aspect to the method whose return type should be modified. You can take a look at my blog post on how to add Spring AOP facet to a Spring application, then write an @Around aspect. I used this aspect for Memoizing results of a method, but in your case, you would take the return value of ProceedingJoinPoint.proceed(), typecast it to appropriate class, then modify it and return it.

In case you plan to return a completely different object altogether, then that would result in ClassCastException, unless the actual returned object is a subclass of the return type.

like image 118
Vikdor Avatar answered Oct 04 '22 03:10

Vikdor