SpringBoot监听器

1.寻找spring.factories配置文件对应的监听器,主要要写监听器的全路径名,不然反射会报错

 

 SpringBoot底层是如何读取META-INF/spring.factories的配置的?

1.遍历所有jar下的META-INF/spring.factories配置文件

2.读取配置文件下的所有属性,放入map

3.配置文件主要来源于,

3.1.开发者自己放的 

 

 3.2 spring-boot的配置文件 

3.spring-boot-autoconfiguration配置文件

读取完后放入缓存中,主要有13个大类,分别是:

org.springframework.context.ApplicationListener             2个值

======================spring-boot================================

org.springframework.boot.env.PropertySourceLoader           2个值
org.springframework.boot.SpringApplicationRunListener       1个值
org.springframework.boot.SpringBootExceptionReporter        1个值
org.springframework.context.ApplicationContextInitializer   4个值
org.springframework.context.ApplicationListener             9个值
org.springframework.boot.env.EnvironmentPostProcessor       3个值
org.springframework.boot.diagnostics.FailureAnalyzer        13个值
org.springframework.boot.diagnostics.FailureAnalysisReporter  1个值

==================spring-boot-autoconfiguration================================

org.springframework.context.ApplicationContextInitializer  2个值
org.springframework.context.ApplicationListener            1个值
org.springframework.boot.autoconfigure.AutoConfigurationImportListener  1个值
org.springframework.boot.autoconfigure.AutoConfigurationImportFilter  3个值
org.springframework.boot.autoconfigure.EnableAutoConfiguration       118个值
org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider 5个值

3个配置文件合并后,

ApplicationContextInitializer  6个值

ApplicationListener               12个值

SpringApplicationRunListener  1个

总共13大类

打开断点看看结果是否匹配:刚好6个,完全匹配

12个监听器:刚好完全匹配

 获取运行时监听器,刚好1个,完全匹配

org.springframework.boot.SpringApplication#getRunListeners

 org.springframework.boot.SpringApplicationRunListeners#starting

发布一个容器启动事件

 这里有四个监听器在监听容器启动事件

猜你喜欢

转载自blog.csdn.net/u012222011/article/details/130005507