开发者社区 问答 正文

从系统变量覆盖application.properties变量

我在config.properties文件中具有以下属性。

resources=/home/pc/work/resources
file1=${resources}/file1
file2=${resources}/file2
file3=${resources}/file3

并加载java.util.Properties以读取这些属性:

properties = new Properties();

    InputStream inputStream = PropertyReader.class.getClassLoader().getResourceAsStream("config.properties");
    try {
        properties.load(inputStream);
    } catch (IOException e) {
        e.printStackTrace();
    }

显然,这将始终直接从文件中读取值。可以resources在保持默认值的情况下将变量覆盖为系统变量吗?

展开
收起
几许相思几点泪 2019-12-23 17:57:49 868 分享 版权
1 条回答
写回答
取消 提交回答
  • 技术架构师 阿里云开发者社区技术专家博主 CSDN签约专栏技术博主 掘金签约技术博主 云安全联盟专家 众多开源代码库Commiter

    说的废话呀。。

    2020-01-04 23:47:00
    赞同 展开评论
问答地址: