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.
Asked
Active
Viewed 2.4k times
1 Answers
28
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.

Vikdor
- 23,934
- 10
- 61
- 84