首页 文章

如何在spring boot中的src / main / resources中的application.properties中替换属性

提问于
浏览
0

我正在使用Spring启动应用程序并在src / main / resources中使用application.properties属性文件 . 它有一些属性需要由外部属性文件替换 . 我将在命令行中传递外部文件位置 .

需要解决方案如何使用外部属性替换应用程序内的属性 .

public static void main(String[] args) throws JMSException, MQException, IOException {

    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    InputStream input = classLoader.getResourceAsStream("Application.properties");
    Properties properties = new Properties();
    properties.load(input);
    properties.load(new FileReader(args[0]));

    SpringApplication springApplication = new SpringApplication(new Object[]{ChapsSchemeFeed.class});
    springApplication.setDefaultProperties(properties);
    springApplication.run(args);
}

在这段代码中,我从命令行读取属性并使用驻留在应用程序中的application.properties加载它们 . 但是当我开始时,它从Application.properties加载属性 . 但我想用命令行属性文件中的属性替换它 .

1 回答

相关问题