我有一些Spring文件依賴於其他文件中的屬性佔位符。從本質上講,我有3個XML文件,像這樣:IoC容器屬性繼承
one.xml:
<?xml version="1.0"?>
<beans ...>
<import resource="two.xml"/>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/your.properties</value>
</list>
</property>
</bean>
<bean id="clasher" class="whatever.Clash">
<property name="name" value="${route.one}"/>
</bean>
</beans>
two.xml:
<?xml version="1.0"?>
<beans ...>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/my.properties</value>
</list>
</property>
</bean>
</beans>
my.properties:
route.one = Why Not?
your.properties:
entirely.unrelated = true
我越來越基本上看起來像這樣的錯誤:
Exception in thread "Launcher:/serverling" org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'clasher' defined in ServletContext resource [/WEB-INF/one.xml]: Could not resolve placeholder 'route.one'
at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:287)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:75)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:663)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:638)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:407)
at org.red5.server.tomcat.TomcatLoader$1.run(TomcatLoader.java:594)
有沒有一種方法,使財產佔位符整個容器繼承?
我最初的假設是,由於容器並不關心哪些文件bean存在,它只會配置所有的bean,然後運行通過容器中的所有定義的bean,並使用多個屬性佔位符配置器來填充它們。
爲什麼不在此示例workingL