[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] @DeclareParents problems

I am having a really difficult time with using the @AspectJ annotated style @DeclareParents. I must be missing something.

I am trying to add a Spring interface (ApplicationContextAware) to several beans so that they automatically have access Spring's ApplicationContext. I would like to do this through an aspect. I implemented the interface like this:

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class ApplicationContextAwareImpl implements ApplicationContextAware {

    // Add ApplicationContext variable
    protected ApplicationContext context = null;
    // setter method for ApplicationContext - required by interface
    public void setApplicationContext( ApplicationContext context ) {
        //this.context = context;

Simple enough. Then I created the aspect like this:

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class Auditor {
    @DeclareParents(value="com.company.*Logic", defaultImpl=ApplicationContextAwareImpl.class)
    public ApplicationContextAware implementedApplicationContextAware;
    @Pointcut("execution( * com.company.*Logic.*(..) )")
    public void method(JoinPoint jp) {}
    public void beforeMethod(JoinPoint jp) {
        System.out.println("target instanceof ApplicationContextAware: " + (jp.getTarget() instanceof ApplicationContextAware));

This too seemed simple enough. But I ended up with these problems using @DeclareParents:
1. If I implement any interface other than a marker interface, the application will not load in Tomcat...I get a 404...(this is a web service using Axis and Spring running on Tomcat)
2. If I implement more than one interface (of course markers only right now), I get the same 404.
3. If I declare more than one parent, I get the 404
4. If I use only a marker interface, it runs, but the jp.getTarget () does not implement the interface (not instance of interface)

Now, here is where it gets really confusing. I decided to implement a similar structure with my own interfaces and all in a separate eclipse project. One interface implemented and declared as a parent. I compiled it and ran it using eclipse. It ran beautifully. I tried other implementations and scenatios. All scenarios above appear to work. WHAT??

So I think whichever aspectj version I am using to weave does not support @DeclareParents. The build must be using a different version from eclipse.

The difference is I use an Ant build to build the real project. So I checked that the Ant build was using the most recent AspectJ compiler. It is using 1.5.0. to be sure I downloaded the most recent. Still no go. What am I missing? It still seems like Eclipse and the Ant build are using different versions of the AspectJ compiler. One supports @DeclareParents and the other does not...

What do you think? I am open to any idea, but very lost at this point.