当前位置: 首页 > news >正文

SpringBoot2.7.9 配置文件加载方式

ConfigDataLocationResolver接口方法说明
isResolvable: 判断是否是需要转换的资源
resolve: 将单个ConfigDataLocation转换为ConfigDataResource集合,在激活环境配置之前加载,也就是profile文件加载之前加载
resolveProfileSpecific: 将单个ConfigDataLocation转换为ConfigDataResource集合,在加载环境配置时(Profiles)进行加载
// 调用resolve将单个ConfigDataLocation转换为ConfigDataResource集合,并且加载文件内容
org.springframework.boot.context.config.ConfigDataImporter#resolveAndLoad

ConfigDataLoader接口方法说明
isLoadable: 是否获取符合条件的ConfigDataLoader
load: 加载配置

ConfigDataResource抽象类:用来描述配置数据资源 optional: 表示是否有指定前缀标记

spring.main.cloud-platform: 配置cloud平台名称
spring.config.name: 配置要加载配置文件的名称,默认值是["application"] org.springframework.boot.context.config.StandardConfigDataLocationResolver#CONFIG_NAME_PROPERTY
spring.config.import、spring.config.additional-location、spring.config.location: 指定要加载的配置文件,优先级如下:
spring.config.import 
spring.config.additional-location
spring.config.location
可以配置多个,默认使用英文分号 ; 分割,也可以自定义解析器(ConfigDataLocationResolver)进行拆分,加载顺序按照拆分后的顺序进行加载,比如:
spring.config.import=import.yaml;import2.yaml;import3.yaml

当配置了spring.config.location时,spring.config.name不生效
当配置了spring.config.location时,默认的org.springframework.boot.context.config.ConfigDataEnvironment#DEFAULT_SEARCH_LOCATIONS不会再加载
org.springframework.boot.context.config.ConfigDataEnvironment#DEFAULT_SEARCH_LOCATIONS包含:
optional:classpath:/;optional:classpath:/config/ 和 optional:file:./;optional:file:./config/;optional:file:./config/*/

spring.config.on-not-found: 配置文件不存在时的策略,参考 org.springframework.boot.context.config.ConfigDataNotFoundAction 枚举类,可以通过SpringApplication.setDefaultProperties 进行设置

spring.profiles.include: 配置要加载的环境, 多个使用逗号分割  比如  a,b 是a和b两个环境
spring.profiles.group: 配置的环境组  spring.profiles.group.x=d,f spring.profiles.group.y=e,g
spring.profiles.active: 激活的环境  多个使用逗号分割  比如  a,b 是a和b两个环境
spring.profiles.default: 默认加载的环境 多个使用逗号分割  比如  a,b 是a和b两个环境
spring.profiles.include和spring.profiles.active都会放在spring.profiles.active集合中
spring.profiles.active和spring.profiles.default同时配置时,默认使用spring.profiles.active,未配置spring.profiles.active时使用spring.profiles.default

profile: 控制拼接指定环境的配置文件,如 dev 生成的配置文件名称为  application-dev.yaml

在springboot中配置文件的加载顺序如下:
yaml yml xml properties
spring.config.name=application(默认配置)
内部默认的配置文件加载顺序
file:/application.yaml
file:/application.yml
file:/application.xml
file:/application.properties
file:./config/application.yaml
file:./config/application.yml
file:./config/application.xml
file:./config/application.properties
file:./config/*/application.yaml
file:./config/*/application.yml
file:./config/*/application.xml
file:./config/*/application.properties
classpath:/application.yaml
classpath:/application.yml
classpath:/application.xml
classpath:/application.properties
classpath:./config/application.yaml
classpath:./config/application.yml
classpath:./config/application.xml
classpath:./config/application.properties
// 默认是 profile是default
file:/application-default.yaml
file:/application-default.yml
file:/application-default.xml
file:/application-default.properties
file:./config/application-default.yaml
file:./config/application-default.yml
file:./config/application-default.xml
file:./config/application-default.properties
file:./config/*/application-default.yaml
file:./config/*/application-default.yml
file:./config/*/application-default.xml
file:./config/*/application-default.properties

 

http://www.lryc.cn/news/179162.html

相关文章:

  • 详解C语言—文件操作
  • IntelliJ IDEA 常用快捷键一览表
  • cola 架构简单记录
  • FFmpeg常用结构体分析
  • ChatGPT 学习笔记 | 什么是 Prompt-tuning?
  • [红明谷CTF 2021]write_shell %09绕过过滤空格 ``执行
  • JVM学习笔记
  • 使用 gst-element-maker 创建一个完全透传的 videofilter 插件
  • 华为ensp单臂路由及OSPF实验
  • Android LiveData 介绍
  • 好看的货架效果(含3D效果)
  • 【每日一题】1498. 满足条件的子序列数目
  • Go语言数据类型实例讲解 - Go语言从入门到实战
  • RocketMQ 事务消息发送
  • 后端-POST请求中只需要两个参数,后端不想创建对象时
  • UG\NX二次开发 通过点云生成曲面 UF_MODL_create_surf_from_cloud
  • Linux常用指令(二)
  • 【HUAWEI】单臂路由
  • 安全学习_开发相关_Java第三方组件Log4jFastJSON及相关安全问题简介
  • 零代码编程:用ChatGPT批量自动下载archive.org上的音频书
  • 力扣用队列实现栈
  • 一朵华为云,如何做好百模千态?
  • 华为云云耀云服务器L实例评测 | 实例使用教学之软件安装:华为云云耀云服务器环境下安装 Docker
  • 小程序编译器性能优化之路
  • FFmpeg 命令:从入门到精通 | ffmpeg 命令分类查询
  • Linux学习记录——삼십일 socket编程---TCP套接字
  • 【学习笔记】深度学习分布式系统
  • 【数据结构】树、二叉树的概念和二叉树的顺序结构及实现
  • rust学习-string
  • No167.精选前端面试题,享受每天的挑战和学习