是否有可能避免@Autowire一些bean,直到其他depeandant bean被創建?讓我用一個例子更好地解釋它:@Autowired和bean創建順序
我有一個創建類型一個有一個名爲一個屬性的對象一個FactoryBean。如果該屬性爲空,則爲該豆分配默認值A。
在@Configuration I類有:
@Autowired private A myBean;
正在發生的事情是,工廠創建bean(我不完全瞭解),但場在工廠是零和我需要它需要另一個豆,它用於創建A。由於它在外部依賴關係中,因此我無法向Factory添加任何註釋。
事情是,我需要在@Autowired請求對象到工廠之前設置值a。有沒有可能給我的限制?
編輯 繼承人的代碼:
@Configuration
@ImportResource("classpath:factory-context.xml")
public class ServiceContextConfig {
@Autowired
private A createdObject;
@Bean(name = "entities-list")
public List<String> getEntity() {
List<String> ls = new ArrayList<String>();
ls.add("countriescatalog");
return ls;
}
然後工廠的context.xml看起來是這樣的:
<bean id="client-factory" class="ClientFactory">
<property name="entities" ref="entities-list"/>
</bean>
其實配置是有點大。我沒有嘗試用這樣的簡單例子。我會嘗試重現它與這樣一個簡單的上下文,看看我是否可以修復它包裝工廠作爲@emd建議
請顯示您的工廠如何創建您的bean,例如。 ''聲明 –
2013-03-21 21:26:39