【问题标题】:Specifying Locations relative to the context XML in Spring在 Spring 中指定相对于上下文 XML 的位置
【发布时间】:2011-02-05 04:16:05
【问题描述】:

有没有办法在相对于 Spring 的上下文文件本身的文件系统(而不是类路径)上引用属性文件?

我想做的是如下:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <!-- I want the below to be relative to this context XML file. -->
            <value>app.properties</value>
        </list>
    </property>
</bean>

我在想像${contextpath} 这样的东西,我可以在上面的“app.properties”前面加上,但找不到任何有用的东西。

谢谢。

【问题讨论】:

  • 你为什么不把路径放在属性文件上,然后用你的spring应用程序来获取它。是一样的吗?您可以动态更改您的属性文件内容值。

标签: java spring contextpath


【解决方案1】:

您可以通过 classpath: 前缀引用类路径上的属性:

<value>classpath:app.properties</value>

【讨论】:

  • 谢谢博佐。您是否知道指定相对于上下文文件而不是类路径的“文件路径”?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-12-27
  • 2015-05-23
  • 2021-04-12
  • 1970-01-01
  • 2016-12-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多