问题描述
一个典型的用例:我有applicationContext.xml
和dispatcher-servlet.xml
.在父级上下文(applicationContext.xml
)中,我有:
A typical use-case: I'm having applicationContext.xml
and dispatcher-servlet.xml
. In the parent context (applicationContext.xml
) I have:
<context:property-placeholder location="classpath:application.properties" />
但是,Web上下文无法访问由它加载的属性-既不能在xml中使用,也不能使用@Value
来访问. (它们只是无法解析,而是将表达式(${varName}
)设置为值)
However, the properties loaded by it are not accessible to the web context - neither in xml, nor using @Value
. (They are just not resolved and the expression (${varName}
) is set as value instead)
我也通过将<context:property-placeholder>
添加到dispatcher-servlet.xml
来解决此问题,但我想知道是否:
I worked it around by adding the <context:property-placeholder>
to dispatcher-servlet.xml
as well, but I wondered whether:
- 这是预期的行为
- 没有更好的方法可以将属性公开给子上下文.
推荐答案
是的,这是预期的行为. <context:property-placeholder>
创建一个BeanFactoryPostProcessor
,该BeanFactoryPostProcessor
在每个上下文中应用.因此,无论如何,您将需要在子上下文中使用后处理器.
Yes, this is an expected behaviour. <context:property-placeholder>
creates a BeanFactoryPostProcessor
which is applied at per-context basis. So, you'll need a postprocessor in the child context anyway.
这篇关于<上下文:属性占位符>子级(Web)上下文无法访问的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!