Announcement Announcement Module
Collapse
No announcement yet.
aspectj/spring again: will aspectj work with proxied bean? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • aspectj/spring again: will aspectj work with proxied bean?

    hello all,
    i have tried one experiment at home (just for sake of trying..). I have an app that is wrapping a DAO into a proxy so that i can use Spring's AOP advice/advisors.
    i have, let's say, a StockDAO to which i wanted to apply an aspect using Spring AOP functionality.
    So, i wrapped my stockDAO into a StockDAOProxy, which has, as target attribute, my StockDAO, and i wrote an advice that is 'called' when method x of stockDAO gets called.

    I then wrote an aspectj aspect, that applies to stockDAO.
    my aspect is a simple trace aspect, which applies to ALL methods of stockDAO.(including method 'x')
    And, i found out that spring aspect is applied correctly when method 'x' of stockDAO is called.
    I was expecting my aspectj aspect to be called before/immediately after the method 'x' has been called on stockDAO.
    I found out, however, that my aspectj is being called only from my Spring aspect, and just because from that aspect i call a method from stockDAO.
    If i didnt call a method from spring advice, my aspectj aspect would'nt have been called at all..
    is it because of the proxy?

    anyone can clarify?

    thanx and regards
    marco

  • #2
    I would expect the AspectJ aspect to be invoked after any Spring advice (and before on the way back if it's around advice). Because AspectJ will not advise the proxy, which is generated at runtime and which it doesn't know about when it weaves at compile time. Essentially AspectJ has modified the behaviour of the target object; Spring has wrapped that target object with a proxy.

    Comment

    Working...
    X