在家長方面,我具有的屬性聲明如下:春季:在孩子方面替代屬性在運行時
<bean id="my.properties"
class="com.rcslabs.webcall.server.property.PropertyPaceholderConfigurer">
<property name="locations" value="classpath:/my.properties"/>
</bean>
後,在運行時,我需要創建一個子上下文,並覆蓋與運行時數據的那些屬性。什麼是最好的方式來做到這一點?
此外:
更確切地說,我手工創建一個子上下文中運行時是這樣的:
ClassPathXmlApplicationContext childAppContext = new ClassPathXmlApplicationContext(parentApplicationContext);
所以,我可以宣佈在childAppContext一個bean,像它通常使用BeanDefinitionRegistry完成?
是的,我實際上使用了一個默認PropertyPlaceholderConfigurer的子類,但是我該如何將**運行時值傳遞給那裏呢?另外,知道如何將某些東西注入到子環境中(並在之後使用它)會很有趣。 系統屬性不起作用,因爲實際上我會有N個子上下文。 – weekens 2012-01-12 12:30:40
@weekens更新了我的回答 – mrembisz 2012-01-12 13:04:02
好吧,它看起來非常好!可能,childAppContext.getBeanFactory()。registerSingleton(...)也可以工作(找不到正確的方法)。非常感謝! – weekens 2012-01-12 13:13:37