【问题标题】:How to load properties from parent module root in Spring如何在 Spring 中从父模块根目录加载属性
【发布时间】:2017-02-12 09:21:59
【问题描述】:

我有一个多模块应用程序,在父应用程序中我有一个用户可以修改的属性文件。在其中一个子模块中,我有一个 spring 项目,它试图加载属性并注入它。

如果我将属性文件移动到 spring 项目的资源目录中,我可以加载并注入它,没有诸如

之类的问题
<util:properties id="properties" location="classpath:service.properties" />

但是用户无法从这里修改这些内容,这很烦人。

还有其他方法可以从父根目录加载属性文件吗?

谢谢

【问题讨论】:

  • 您可以使用 file: 前缀从文件系统加载属性,例如 location="file:/service.properties" ?
  • 如果你回答这个我可以将其标记为正确答案:)

标签: java spring properties classpath


【解决方案1】:

如果你使用的是 maven,你可以使用

<resource> <directory>your Resource</directory> <filtering>false</filtering> </resource>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-01
    • 2018-03-28
    • 2021-05-02
    • 2017-07-25
    • 1970-01-01
    • 1970-01-01
    • 2019-11-10
    • 1970-01-01
    相关资源
    最近更新 更多