Announcement Announcement Module
No announcement yet.
[noob] trouble getting concrete class proxied Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • [noob] trouble getting concrete class proxied

    I just started playing with Spring AOP yesterday, so please bare with me. I have a couple questions that I'm sure one the guru's could answer pretty easily.

    We have some domain objects that do not implement any interfaces. They are persisted in LDAP and I'd like to implement lazy loading for some of the related data, also in LDAP.

    I have developed/configured a test aspect that is triggered by a pointcut on an interface method call, but I have not been able to figure out how to get a regular domain object method call wrapped.

    I added the attribute proxy-target-class="true" to the aop:config tag, but it didn't make any difference. I know a method is being called, because I have a log entry made within the call. I do not see the aspect log entry in this case, so I must have something wrong in the config, which looks very much like the following:

    <bean id="domObj" class="" scope="prototype" />
    <aop:config proxy-target-class="true">
      <aop:pointcut id="testPointcut"
          expression="execution(**(..))" />
      <aop:aspect id="testAspect" ref="ldapLazyLoader">
        <aop:before pointcut-ref="testPointcut" method="doLogMethodCall" />
    The ldapLazyLoader ref is a normal POJO, without @Aspect annotations. The methods in it only make log entries at this time. I just want to get to the point were the aspect is being executed properly before adding the real code.

    I also tried expression="bean(domObj)" for the pointcut, but I'm pretty sure that's not correct and it didn't work.

    FYI, the technology in use is:
    • tomcat 6.0.14
    • spring 2.5.x
    • cglib-2.1.3
    • aspectjrt and aspectjweaver that comes with spring 2.5.x
    So, I have the following questions:

    1) what's wrong with my config?

    2) do I have to define a bean for each and every object (Interface or regular class - e.g. a domain object) that I want to provide aspect advice to?

    3) I tried to see debug info in the log (log4j is in use) for org.aspectj, but I can't seem to get ANY output from those classes during startup or runtime. Should I be able to see startup and/or runtime debug messages from aspectj?


  • #2
    Spring AOP uses a proxy based approach, this has as a drawback that it can only advice beans it knows about. Your domain objects are created on the fly outside of your applicationcontext, so spring cannot do any aop stuff on them.

    If you want that you will need load- or compiletime weaving with for instance AspectJ.


    • #3
      So, if I wanted to be able to accomplish the lazy loading goal, would it be reasonable to do the following:
      • create a factory (bean) for the domain objects in question (there are only two at the moment)
      • create an interface and implementation (bean) for those domain objects
      • refactor all "new DomainObject" ref's to use the factory
      • refactor, if necessary all DomainObject.methodCall() ref's to use the interface
      I assume the factory would need to ask spring to hand it a new domain object each time one is needed in order to proxy that object.

      If I do this, assuming that work does not take too much time, then I think Spring AOP will work. But, is there another approach (in general) that anyone could offer as a better strategy for accomplishing the main goal? How does the above approach compare to using AspectJ as noted in the previous reply?