代码之家  ›  专栏  ›  技术社区  ›  Daisuke Shimamoto

在Spring中指定相对于上下文XML的位置

  •  2
  • Daisuke Shimamoto  · 技术社区  · 14 年前

    有没有一种方法可以相对于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”,但找不到任何有用的东西。

    谢谢。

    1 回复  |  直到 13 年前
        1
  •  0
  •   Bozho    14 年前

    您可以通过 classpath: 前缀:

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