springboot2.2.6.RELEASE chapter12 配置文件目录加载顺序

spring.config.name and spring.config.location are used very early to determine
which files have to be loaded. They must be defined as an environment property
(typically an OS environment variable, a system property, or a command-line
argument).
If spring.config.location contains directories (as opposed to files), they should end in / (and, at
runtime, be appended with the names generated from spring.config.name before being loaded,
including profile-specific file names). Files specified in spring.config.location are used as-is, with
no support for profile-specific variants, and are overridden by any profile-specific properties.
Config locations are searched in reverse order. By default, the configured locations are
classpath:/,classpath:/config/,file:./,file:./config/. The resulting search order is the following:

  1. file:./config/
  2. file:./
  3. classpath:/config/
  4. classpath:/

When custom config locations are configured by using spring.config.location, they replace the
default locations. For example, if spring.config.location is configured with the value
classpath:/custom-config/,file:./custom-config/, the search order becomes the following:

  1. file:./custom-config/
  2. classpath:custom-config/

Alternatively, when custom config locations are configured by using spring.config.additionallocation,
they are used in addition to the default locations. Additional locations are searched before
the default locations. For example, if additional locations of classpath:/customconfig/,
file:./custom-config/ are configured, the search order becomes the following:

  1. file:./custom-config/
  2. classpath:custom-config/
  3. file:./config/
  4. file:./
  5. classpath:/config/
  6. classpath:/
    This search ordering lets you specify default values in one configuration file and then selectively
    override those values in another. You can provide default values for your application in
    application.properties (or whatever other basename you choose with spring.config.name) in one of
    the default locations. These default values can then be overridden at runtime with a different file
    located in one of the custom locations.
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容