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

发布于 2024-08-28 03:21:13 字数 548 浏览 4 评论 0 原文

有没有办法引用文件系统上(而不是类路径上)相对于 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”之前,但找不到任何有用的东西。

谢谢。

Is there a way to reference a properties file on a file system (not on a classpath) relative to the Spring's context file itself?

What I want to do is the below:

<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>

I was imagining something like ${contextpath} that I could prepend to the above "app.properties" but couldn't find anything helpful.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

记忆之渊 2024-09-04 03:21:13

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

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

You can reference properties on the classpath via the classpath: prefix:

<value>classpath:app.properties</value>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文