<上下文:属性占位符>子级(Web)上下文无法访问的属性

编程入门 行业动态 更新时间:2024-10-09 02:26:45
本文介绍了<上下文:属性占位符>子级(Web)上下文无法访问的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

    更多推荐

    &lt;上下文:属性占位符&gt;子级(Web)上下文无法访问的属性

    本文发布于:2023-11-09 07:59:21,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1571807.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:上下文   属性   无法访问   lt   amp

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!