我有许多依赖于其他文件中的属性占位符的 Spring 文件。本质上,我有 3 个 XML 文件,如下所示:
一个.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>
二.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>
我的属性:
route.one = Why Not?
你的属性:
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,并使用多个属性占位符配置器来填充它们。
为什么这个例子不起作用L