随笔记录

编程入门 行业动态 更新时间:2024-10-15 16:20:52

<a href=https://www.elefans.com/category/jswz/34/1769507.html style=随笔记录"/>

随笔记录

SimpleApplicationEventMulticaster、 BootstrapApplicationListener、ConfigFileApplicationListener

加载流程

SpringApplication#run(java.lang.Class<?>[], java.lang.String[])
SpringApplication#run(java.lang.String…)
SpringApplication#prepareEnvironment
org.springframework.boot.SpringApplicationRunListeners#environmentPrepared
org.springframework.boot.context.event.EventPublishingRunListener#environmentPrepared
SimpleApplicationEventMulticaster#multicastEvent(ApplicationEvent, ResolvableType)
SimpleApplicationEventMulticaster#doInvokeListener

getApplicationListeners

BootstrapApplicationListener#onApplicationEvent

BootstrapApplicationListener#bootstrapServiceContext

添加一个名为bootstraporg.springframework.core.env.MapPropertySourceorg.springframework.core.env.MutablePropertySources,其中配置了spring.config.namebootstrap
中间执行下文逻辑
方法最后又会移除bootstraporg.springframework.core.env.MapPropertySource

org.springframework.boot.builder.SpringApplicationBuilder#run

this.build().run(args) 复用 SpringApplication#run 方法
SpringApplication#run(java.lang.String…)
SpringApplication#prepareEnvironment
org.springframework.boot.SpringApplicationRunListeners#environmentPrepared
org.springframework.boot.context.event.EventPublishingRunListener#environmentPrepared
SimpleApplicationEventMulticaster#multicastEvent(ApplicationEvent, ResolvableType)
SimpleApplicationEventMulticaster#doInvokeListener


ConfigFileApplicationListener#onApplicationEvent
ConfigFileApplicationListener#onApplicationEnvironmentPreparedEvent
ConfigFileApplicationListener#postProcessEnvironment
ConfigFileApplicationListener#addPropertySources
ConfigFileApplicationListener.Loader#load()

加载一些列配置文件

ConfigFileApplicationListener.Loader#load(ConfigFileApplicationListener.Profile, ConfigFileApplicationListener.DocumentFilterFactory, ConfigFileApplicationListener.DocumentConsumer)

  1. 获取各种路径

通过 ConfigFileApplicationListener.Loader#getSearchLocations() 源码:
获取spring.config.additional-location配置的路径。若spring.config.location存在,再将其配置的路径加入;否则加入classpath:/,classpath:/config/,file:./,file:./config/*/,file:./config/这些默认路径。

  1. 获取各种配置文件名称

通过 ConfigFileApplicationListener.Loader#getSearchNames() 源码:
spring.config.name存在,获取其配置的内容作为名称列表;否则就获取 ConfigFileApplicationListener.this.names 和 application作为名称列表。

备注:

  • spring.config.name在 BootstrapApplicationListener#bootstrapServiceContext 中就设置为bootstrap
  • 当 BootstrapApplicationListener#bootstrapServiceContext 执行之后,移除了bootstrap,此时环境变量就不存在spring.config.name(前提是没有手动配置过),所以拿到的文件名称就是默认的application
  1. 加载单一路径单一文件配置

    ConfigFileApplicationListener.Loader#load(java.lang.String, java.lang.String, ConfigFileApplicationListener.Profile, ConfigFileApplicationListener.DocumentFilterFactory, ConfigFileApplicationListener.DocumentConsumer)

加载bootstrap配置大致流程


更多推荐

随笔记录

本文发布于:2023-11-16 03:22:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1612188.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:随笔

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!