When using AUTOWIRE_NO in combination with dependency checking one would only expect dependency checking to be performed for properties that would actually be set (ie. properties annotated with @Autowired). However this does not seem to be the case. Doing something similar to the following will result in a dependency error for the logger property of the NonSpringAwareBaseClass.
public abstract class NonSpringAwareBaseClass {
private Logger log;
public void setLogger(Logger aLogger) {
log = aLogger;
}
// ...
}
public class IKnowAboutSpring extends NonSpringAwareBaseClass {
private SomeClass myObj;
@Autowired
public void setMyObject(SomeClass aObj) {
myObj = aObj;
}
}
public class Main {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath*:resources/applicationContext-*.xml");
AutowireCapableBeanFactory factory = ctx.getAutowireCapableBeanFactory();
IKnowAboutSpring populateMeSpring = new IKnowAboutSpring();
factory.autowireBeanProperties(populateMeSpring, AutoWireCapableBeanFactory.AUTOWIRE_NO, true);
}
}
This is unfortunately as defined: The dependency-check flag applies to all bean properties, independent from how they might get populated. I would not recommend using this in combination with @Autowired: That annotation has its own "required" attribute. We also got @Required for marking bean properties which are supposed to be populated through external metadata. From our perspective, in combination with annotation-driven injection, there is no need to use the old dependency-check flag anymore.
Juergen