24

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.

Vikdor
  • 23,934
  • 10
  • 61
  • 84
cleverUtd
  • 301
  • 1
  • 3
  • 9
  • 2
    I cannot help you with Spring AOP, but I highly suggest that you post some source code if you ever want help from the Stackoverflow community. – ecbrodie Dec 24 '12 at 06:33

1 Answers1

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