Announcement Announcement Module
Collapse
No announcement yet.
@Configurable not working on Subclass of an Abstract Class in specific case Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Configurable not working on Subclass of an Abstract Class in specific case

    I believe I have narrowed this issue down to a specific case. Take the following general abstract class:

    Code:
    public abstract class AbstractClass {
    //Irrelevant 
    }
    And a subclass of that AbstractClass that is marked as configurable:

    Code:
    @Configurable(autowire = Autowire.BY_TYPE)
    public class SubClass extends AbstractClass {
    
       @Autowired
       private SomeService someService;
    
    }
    The following instantiation of SubClass fails to autowire the dependencies:

    Code:
    //The key here is to define AbstractClass as the type, but invoke the SubClass constructor via the new operator
    AbstractClass abstractClass = new SubClass();
    However, the both of the following instantiations successfully autowire the dependencies:

    Code:
    //Defining SubClass as the type allows weaving to work
    SubClass subClass = new SubClass();
    
    //or using the newInstance method on the SubClass class definition, even when the defined type is AbstractClass
    AbstractClass abstractClass = SubClass.class.newInstance();
    For completeness, I'm using Spring 3.2.2.RELEASE, aspectjrt and aspectjtools v1.7.0. I'm using load time weaving with the spring-instrument-tomcat.jar via the META-INF/context.xml, running on Tomcat 7.0.32:

    Code:
    <Context>
    	<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader" />
    </Context>
    Does this look like a bug? Or is it expected that invoking the constructor for SubClass assigning to the AbstractClass variable will not weave?
Working...
X