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
添加一个名为
bootstrap
的org.springframework.core.env.MapPropertySource
给org.springframework.core.env.MutablePropertySources
,其中配置了spring.config.name
为bootstrap
。
中间执行下文逻辑
方法最后又会移除bootstrap
的org.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)
通过 ConfigFileApplicationListener.Loader#getSearchLocations() 源码:
获取spring.config.additional-location
配置的路径。若spring.config.location
存在,再将其配置的路径加入;否则加入classpath:/,classpath:/config/,file:./,file:./config/*/,file:./config/
这些默认路径。
通过 ConfigFileApplicationListener.Loader#getSearchNames() 源码:
若spring.config.name
存在,获取其配置的内容作为名称列表;否则就获取 ConfigFileApplicationListener.this.names 和application
作为名称列表。
备注:
spring.config.name
在 BootstrapApplicationListener#bootstrapServiceContext 中就设置为bootstrap
spring.config.name
(前提是没有手动配置过),所以拿到的文件名称就是默认的application
加载单一路径单一文件配置
ConfigFileApplicationListener.Loader#load(java.lang.String, java.lang.String, ConfigFileApplicationListener.Profile, ConfigFileApplicationListener.DocumentFilterFactory, ConfigFileApplicationListener.DocumentConsumer)
加载bootstrap配置大致流程