AspectJ and Spring LTW doesn't work when upcasting
I setup LTW with AspectJ and spring pretty quick and successfull. Here is the setup:
beans.xml:

    <context:annotation-config />
    <aop:aspectj-autoproxy />
    <context:spring-configured />
    <context:load-time-weaver />
    <context:component-scan base-package="com.test.service" />

My service that will be autowired to a class:

    @Service
    public class MyService {
    }

Parent class:

    public class Bar {
    }

The configurable class, that autowires the service and extends Bar.

    @Configurable
    public class BarExtended extends Bar{
    	@Autowired
    	private MyService service;
    	public MyService getWeavedInObject(){
    		return service;
    	}
    }

And just a class that has got a referance to the parent class Bar:

    public class Foo {
    	private Bar bar;
    	public void setBar(Bar bar) {
    		this.bar = bar;
    	}
    }

And a successfull test case. It just creates a instance of BarExtended and checks if the LTW worked. The Foo class does nothing.

    @Test
    public void simple(){
    	Foo foo = new Foo();
    	BarExtended barExtended = new BarExtended();
    	assertNotNull("LTW didn't work.", barExtended.getWeavedInObject());
    }

This test runs green. BUT following test failes:

    @Test
    public void simple(){
    	Foo foo = new Foo();
    	BarExtended barExtended = new BarExtended();
    	foo.setBar(barExtended);
    	assertNotNull("LTW didn't work.", barExtended.getWeavedInObject());
    }
I just insert the line where the class BarExtended is set to Foo. The downcast make the AspjectJ not working.

BTW, when I change the Foo class to use the BarExtended class (so no upcasting is needed):

    public class Foo {
    	private BarExtended bar;
    	public void setBar(BarExtended bar) {
    		this.bar = bar;
    	}
    }
The above test will work. Does anyone has an idea why AspjectJ behaves so strange, when a configurable object is upcasted?

Thanks a lot

Regards,

Andreas


AspectJ and Spring LTW doesn't work when upcasting
===

I setup LTW with AspectJ and spring pretty quick and successfull. Here is the setup:
beans.xml:

    <context:annotation-config />
    <aop:aspectj-autoproxy />
    <context:spring-configured />
    <context:load-time-weaver />
    <context:component-scan base-package="com.test.service" />

My service that will be autowired to a class:

    @Service
    public class MyService {
    }

Parent class:

    public class Bar {
    }

The configurable class, that autowires the service and extends Bar.

    @Configurable
    public class BarExtended extends Bar{
    	@Autowired
    	private MyService service;
    	public MyService getWeavedInObject(){
    		return service;
    	}
    }

And just a class that has got a referance to the parent class Bar:

    public class Foo {
    	private Bar bar;
    	public void setBar(Bar bar) {
    		this.bar = bar;
    	}
    }

And a successfull test case. It just creates a instance of BarExtended and checks if the LTW worked. The Foo class does nothing.

    @Test
    public void simple(){
    	Foo foo = new Foo();
    	BarExtended barExtended = new BarExtended();
    	assertNotNull("LTW didn't work.", barExtended.getWeavedInObject());
    }

This test runs green. BUT following test failes:

    @Test
    public void simple(){
    	Foo foo = new Foo();
    	BarExtended barExtended = new BarExtended();
    	foo.setBar(barExtended);
    	assertNotNull("LTW didn't work.", barExtended.getWeavedInObject());
    }
I just insert the line where the class BarExtended is set to Foo. The downcast make the AspjectJ not working.

BTW, when I change the Foo class to use the BarExtended class (so no upcasting is needed):

    public class Foo {
    	private BarExtended bar;
    	public void setBar(BarExtended bar) {
    		this.bar = bar;
    	}
    }
The above test will work. Does anyone has an idea why AspjectJ behaves so strange, when a configurable object is upcasted?

Thanks a lot

Regards,

Andreas

