Issue Details (XML | Word | Printable)

Key: SPR-6818
Type: Bug Bug
Status: Resolved Resolved
Resolution: Won't Fix
Priority: Minor Minor
Assignee: Juergen Hoeller
Reporter: Philip Graham
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Spring Framework

Unexpected behaviour when using AUTOWIRE_NO in combination with dependency checking

Created: 09/Feb/10 03:47 PM   Updated: 10/Feb/10 05:52 AM   Resolved: 10/Feb/10 05:52 AM
Component/s: SpringCORE
Affects Version/s: 2.5.6
Fix Version/s: None

Time Tracking:
Not Specified

Environment: N/A


 Description  « Hide

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); }
}



Juergen Hoeller added a comment - 10/Feb/10 05:52 AM

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