Question about Spring 3 autoscan and annotation required

I have a class annotated with spring Component for example:

 @Component public class ImportantClass{ @Autowired private DependentClassIF otherClass; //getters setters @Required public void setOtherClass(DependentClassIF c){ this.otherClass = c; } 

 public interface DependentClassIF { //methods here } @Component public class DependentClass implements DependentClassIF { //implementation here } 

I use autoscan to detect beans instead of declaring them all in the conf bean file.
I get

org.springframework.beans.factory.BeanInitializationException: The property "otherClass" is required for the Important Information bean

My question is: In autoscan, not spring, make sure all required properties are inserted?
If I remove @Required , it works, but I'm not sure that I understand spring behavior.

Any input is welcome.

thanks

+4
source share
1 answer

@Autowired is required true, so you don't need @Required

You don't need @Requried with annotation-based injection. It is intended for use with xml configuration to indicate that the property should be set to xml.

+3
source

All Articles