欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

spring boot 配置 spring.config.location

程序员文章站 2022-04-06 18:48:49
...

1 . 2.x版本

   spring.config.location 设置后,只读取这个文件配置内容,不再读取其他地址的配置文件

     根据官方文档表述,默认会读取

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

 在使用 spring.config.location 指定外部配置文件时,需要此份配置文件需全量满足当前工程运行时所需,因为它不会去与 resources 目录下的配置文件去做 merge 操作。

2.  spring.config.additional-location

  配置后加载顺序,属性会merge. 同名属性以优先级高的为准

1. file:./custom-config/
2. classpath:custom-config/
3. file:./config/
4. file:./config/*/
5. file:./
6. classpath:/config/
7. classpath:/

 3. spring.profiles.active

        springboot 默认是在src/main/resources文件夹中加载application.properties默认配置文件,格式为application-{profile}.properties,其中{profile}对应你的环境标识

     在application.properties中添加spring.profiles.active = dev,database

In addition to application.properties files, profile-specific properties can also be defined by using
the following naming convention: application-{profile}.properties. The Environment has a set of
default profiles (by default, [default]) that are used if no active profiles are set. In other words, if
55no profiles are explicitly activated, then properties from application-default.properties are
loaded.
相关标签: 框架开发