• 微信公众号:美女很有趣。 工作之余,放松一下,关注即送10G+美女照片!

springboot配置优先级

开发技术 开发技术 1个月前 (05-14) 12次浏览

main:11, ServerApplication
run:1230, SpringApplication
run:1242, SpringApplication
run:297, SpringApplication
prepareEnvironment:338, SpringApplication
environmentPrepared:54, SpringApplicationRunListeners
environmentPrepared:74, EventPublishingRunListener
multicastEvent:127, SimpleApplicationEventMulticaster
multicastEvent:139, SimpleApplicationEventMulticaster
invokeListener:165, SimpleApplicationEventMulticaster
doInvokeListener:172, SimpleApplicationEventMulticaster
onApplicationEvent:171, ConfigFileApplicationListener
onApplicationEnvironmentPreparedEvent:185, ConfigFileApplicationListener
postProcessEnvironment:198, ConfigFileApplicationListener
addPropertySources:215, ConfigFileApplicationListener
load:343, ConfigFileApplicationListener$Loader
将下面2个自定义的文件解析并放入environment中。这里已经决定
application.properties
application-dev.properties

会有2次加载apollo默认的空间:
第一次:默认加载application
run:1230, SpringApplication
run:1242, SpringApplication
run:305, SpringApplication
prepareContext:364, SpringApplication
applyInitializers:628, SpringApplication
initialize:82, ApolloApplicationContextInitializer
initialize:103, ApolloApplicationContextInitializer
第二次:根据@EnableApolloConfig配置的值决定,如果没有值,默认加载application
run:1230, SpringApplication
run:1242, SpringApplication
run:307, SpringApplication
refreshContext:386, SpringApplication
refresh:754, SpringApplication
refresh:142, ServletWebServerApplicationContext
refresh:533, AbstractApplicationContext
invokeBeanFactoryPostProcessors:706, AbstractApplicationContext
invokeBeanFactoryPostProcessors:162, PostProcessorRegistrationDelegate
invokeBeanFactoryPostProcessors:282, PostProcessorRegistrationDelegate
postProcessBeanFactory:67, PropertySourcesProcessor
initializePropertySources:74, PropertySourcesProcessor

environment->propertySources中的propertySourceList集合元素的优先级来确定配置项,相同配置项取propertySourceList集合中在前面的一个。

apollo>application-dev.properties>application.properties>bootstrap.properties  这个优先级是指取值的优先级,不是文件加载的优先级


程序员灯塔
转载请注明原文链接:springboot配置优先级
喜欢 (0)