4
我有一个类注释与春天Component
例如:问题上的弹簧3自动扫描和需要注解
@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
}
我用自动扫描检测豆,而不是宣布他们都在bean的conf文件。
我得到
org.springframework.beans.factory.BeanInitializationException: Property 'otherClass' is required for bean 'ImportantClass'
我的问题是: 在自动扫描,并放不是春确保所有需要属性注入?
如果我删除了@Required
它可行,但我不确定我是否理解Spring的行为。
欢迎任何输入。
感谢
你的意思是2个注释在同一个地方吗?如果我在'private DependentClassIF otherClass上执行'@Autowired @ Required';'我得到错误:'注释@Required不允许用于这个位置' – Cratylus 2011-06-13 10:25:27
@ user384706看到更新 – Bozho 2011-06-13 10:37:12