What is the difference between putting a property on application.yml or bootstrap.yml in spring boot?

前端 未结 8 801
慢半拍i
慢半拍i 2020-12-02 03:13

What is the difference between putting a property on application.yml or bootstrap.yml in spring boot? In logging.config case, the application works different.

8条回答
  •  星月不相逢
    2020-12-02 04:14

    Well, I totally agree with answers already exist on this point:

    • bootstrap.yml is used to save parameters that point out where the remote configuration is and Bootstrap Application Context is created with these remote configuration.

    Actually, it is also able to store normal properties just the same as what application.yml do. But pay attention on this tricky thing:

    • If you do place properties in bootstrap.yml, they will get lower precedence than almost any other property sources, including application.yml. As described here.

    Let's make it clear, there are two kinds of properties related to bootstrap.yml:

    • Properties that are loaded during the bootstrap phase. We use bootstrap.yml to find the properties holder (A file system, git repository or something else), and the properties we get in this way are with high precedence, so they cannot be overridden by local configuration. As described here.
    • Properties that are in the bootstrap.yml. As explained early, they will get lower precedence. Use them to set defaults maybe a good idea.

    So the differences between putting a property on application.yml or bootstrap.yml in spring boot are:

    • Properties for loading configuration files in bootstrap phase can only be placed in bootstrap.yml.
    • As for all other kinds of properties, place them in application.yml will get higher precedence.

提交回复
热议问题