我使用自己的REST接口擴展名爲Hippo CMS的完整產品。 Hippo CMS使用Apache CXF進行休眠,並從Hippo CMS資源中定義的spring bean獲取資源定義。此定義如下所示:在基於java的配置中重寫xml定義的spring bean
<bean id="jaxrsRestPlainResourceProviders" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="org.apache.commons.collections.ListUtils" />
<property name="targetMethod" value="union" />
<property name="arguments">
<list>
<ref bean="customRestPlainResourceProviders" />
<ref bean="defaultRestPlainResourceProviders" />
</list>
</property>
</bean>
<bean id="defaultRestPlainResourceProviders" class="org.springframework.beans.factory.config.ListFactoryBean">
<property name="sourceList">
<list>
</list>
</property>
</bean>
<!-- Default empty list of custom plain resource providers to be overriden. -->
<bean id="customRestPlainResourceProviders" class="org.springframework.beans.factory.config.ListFactoryBean">
<property name="sourceList">
<list>
</list>
</property>
</bean>
我需要用我自己的bean覆蓋customRestPlainResourceProviders
bean。它看起來像這樣工作正常,從XML配置:
<bean id="customRestPlainResourceProviders" class="org.springframework.beans.factory.config.ListFactoryBean">
<property name="sourceList">
<list>
<bean class="org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider">
<constructor-arg>
<bean class="com.xxx.rest.FolderStructureResource"/>
</constructor-arg>
</bean>
</list>
</property>
</bean>
但它不工作,如果我定義的Java配置類的Bean(這在其他豆類的情況下工作完全正常):
@Bean(name = "customRestPlainResourceProviders")
public ListFactoryBean customRestPlainResourceProviders() {
ListFactoryBean listFactoryBean = new ListFactoryBean();
listFactoryBean.setSourceList(
Lists.newArrayList(
new SingletonResourceProvider(
new FolderStructureResource(repository())
)
)
);
return listFactoryBean;
}
有沒有辦法用Java配置類中創建的bean重寫XML配置中定義的bean?
檢查彈簧是否配置爲掃描指定的類或包 –
這是因爲配置本身工作正常。我可以在這個基於java的配置中定義一個bean,並自動在例如FolderStructureResource在xml中定義。 –
xml不需要掃描java類。基於註解需要在春季進行掃描。檢查 標記 –