<上下文:属性占位符>子级(Web)上下文无法访问的属性 [英] <context:property-placeholder> properties not accessible to the child (web) context

查看:133
本文介绍了<上下文:属性占位符>子级(Web)上下文无法访问的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个典型的用例:我有applicationContext.xmldispatcher-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:

  1. 这是预期的行为
  2. 没有更好的方法可以将属性公开给子上下文.

推荐答案

是的,这是预期的行为. <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.

这篇关于&lt;上下文:属性占位符&gt;子级(Web)上下文无法访问的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆