一个典型的用例:我有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)上下文无法访问的属性
发布评论