配置文件的加载顺序
| 12
 3
 4
 5
 
 | <includes><include>**/application*.yml</include>
 <include>**/application*.yaml</include>
 <include>**/application*.properties</include>
 </includes>
 
 | 
外部约定配置文件加载顺序
优先级由底到高,高优先级的配置会覆盖低优先级的配置;互补配置;
| 12
 3
 4
 5
 6
 7
 
 | optional:classpath:/optional:classpath:/config/
 optional:file:./
 optional:file:./config/*/
 optional:file:./config/
 optional:classpath:custom-config/      --spring.config.location
 optional:file:./custom-config/         --spring.config.location
 
 | 
- classpath根目录下的
- classpath根config/
- 项目根目录(如果当前项目是继承/耦合 关系maven项目的话,项目根目录=父maven项目的根目录)
- 项目根目录/config
- 直接子目录/config 
| 1
 | java -jar xxxx.jar --spring.config.location=D:\config/
 | 
所有配置文件按以下顺序考虑: 优先级从低到高
- 打包在jar中配置文件  
- 打包在jar中profile 
- 打包的jar之外的配置文件
- 打包的jar之外的profile
配置文件加载顺序
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 
 | <include>**/application*.yml</include><include>**/application*.yaml</include>
 <include>**/application*.properties</include>
 
 optional:classpath:/
 optional:classpath:/config/
 optional:file:./
 optional:file:./config/*/
 optional:file:./config/
 optional:classpath:custom-config/      --spring.config.location
 optional:file:./custom-config/         --spring.config.location
 
 所有配置文件按以下顺序考虑: 优先级从低到高
 打包在jar中配置文件
 打包在jar中profile
 打包的jar之外的配置文件
 打包的jar之外的profile
 
 | 
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
             
            
            
            
    
      
        
      
    
                
            
            
        
Copyright 2021 sunfy.top ALL Rights Reserved