Skip to main content

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


> 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...

AJDT does not always get updated for every single dev build of the AspectJ compiler available from the eclipse.org/aspectj download page.  AspectJ dev builds are constantly updated from CVS, then when we have what we think is a good candidate, we put it into AJDT and do some extra testing before releasing it.

On @DeclareParents, I do know there were problems at 1.5.0 final release but we have fixed a number of issues since then.  AJDT was refreshed last week to include the latest AspectJ and since then nothing has changed with respect to DeclareParents.  So, I'm confused if the latest AJDT build and the latest AspectJ build are behaving differently with respect to @DeclareParents.


On 27/03/06, Scott <aspectj-users@xxxxxxxxxxx> wrote:
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;

@Aspect
public class Auditor {
   
    @DeclareParents(value="com.company.*Logic", defaultImpl=ApplicationContextAwareImpl.class)
    public ApplicationContextAware implementedApplicationContextAware;
   
    @Pointcut("execution( * com.company.*Logic.*(..) )")
    public void method(JoinPoint jp) {}
       
    @Before("method(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.

-Scott

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users




Back to the top