Spring boot external application.properties

前端 未结 5 680
长发绾君心
长发绾君心 2020-12-15 22:20

I am developing a spring boot application

I want to override some properties in src/main/resources/application.properties with an external file (e.g.

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-15 23:02

    I always use --spring.config.location= in the command line as specified in the documentation, and you can put various files in this, one with default values and another with the overridden ones.

    Edit:
    Alternatively, you could also use something like :

    @PropertySources({
        @PropertySource("classpath:default.properties")
        , @PropertySource(value = "file:${external.config}", ignoreResourceNotFound = true)
    })
    

    and specify a external.config in your application.properties.
    This would provide a default path for overridding config, that is still overriddable itself by specifying a --external.config in the command line.
    I use this with ${external.config} being defined as a system env variable, but it should work with a application.properties variable too.

提交回复
热议问题