【问题标题】:How to springboot custom configuration file path?spring boot如何自定义配置文件路径?
【发布时间】:2021-02-02 16:55:59
【问题描述】:

由于我的项目有多个环境和多个小项目组,我需要根据不同的属性名来处理相应的业务逻辑,但是在bootstrap.yml中找不到任何可以设置自定义配置文件路径的参数。

google了一下,只找到了通过启动类修改自定义配置文件路径的方法

还有其他更好的方法来配置它吗?请帮帮我!

【问题讨论】:

  • @ConditionalOnProperty?还是我错过了什么?
  • @Eugene 我有三个不同的配置选项,我启动maven时需要根据spring.profiles.active指定要加载哪个配置文件

标签: java spring spring-boot


【解决方案1】:

Spring Boot 在四个预定中寻找你的外部化配置文件 地点:

  • 在类路径根目录中,

  • 在类路径的包/config中,

  • 在当前目录中

  • 在当前目录的 /config 子目录中。

    我想你想从 /config 文件夹加载配置文件。

您可以通过编程方式告诉 Spring Boot 从 自定义位置如下:

ConfigurableApplicationContext applicationContext = new SpringApplicationBuilder(Application.class)
                .properties("spring.config.name:application,conf",
                        "spring.config.location:classpath:/your/location/of/config/folder,classpath:/another/location/of/congig/folder")
                .build().run(args);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-09
    • 1970-01-01
    • 2018-12-24
    • 2020-02-02
    • 2021-10-21
    • 2018-12-11
    • 2020-11-06
    • 2020-11-09
    相关资源
    最近更新 更多