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