spring.factories分析

  1. 进入spring.factories文件,具体可看下图:
    spring.factories分析_第1张图片
    分析,拆解各部分
  2. PropertySourceLoader表示SpringBoot配置文件支持的格式,配置文件内置支持properties、xml、yml和yaml几种格式。
# PropertySource Loaders
org.springframework.boot.env.PropertySourceLoader=\
org.springframework.boot.env.PropertiesPropertySourceLoader,\
org.springframework.boot.env.YamlPropertySourceLoader
  1. 运行的监听器类,EventPublishingRunListener是在run方法执行到不同的阶段中,发布相应的event给SpringApplication对象的Listeners中记录的事件监听器。
# Run Listeners
org.springframework.boot.SpringApplicationRunListener=\
org.springframework.boot.context.event.EventPublishingRunListener
  1. 应用程序初始化类,ConfigurationWarningsApplicationContextInitializer是报告常见的配置错误;ContextIdApplicationContextInitializer是给ApplicationContext设置一个ID;DelegatingApplicationContextInitializer是将初始化的工作交给context.initializer.classes环境变量指定的初始化器;ServerPortInfoApplicationContextInitializer的作用是监听EmbeddedServletContainer InitializedEvent类型的事件,然后将内嵌的Web服务器使用的端口设置到ApplicationContext中。
# Application Context Initializers
org.springframework.context.ApplicationContextInitializer=\
org.springframework.boot.context.ConfigurationWarningsApplicationContextInitializer,\
org.springframework.boot.context.ContextIdApplicationContextInitializer,\
org.springframework.boot.context.config.DelegatingApplicationContextInitializer,\
org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer
  1. 应用程序监听器
# Application Listeners
org.springframework.context.ApplicationListener=\
org.springframework.boot.ClearCachesApplicationListener,\
org.springframework.boot.builder.ParentContextCloserApplicationListener,\
org.springframework.boot.context.FileEncodingApplicationListener,\
org.springframework.boot.context.config.AnsiOutputApplicationListener,\
org.springframework.boot.context.config.ConfigFileApplicationListener,\
org.springframework.boot.context.config.DelegatingApplicationListener,\
org.springframework.boot.context.logging.ClasspathLoggingApplicationListener,\
org.springframework.boot.context.logging.LoggingApplicationListener,\
org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener
  1. 动态读取文件
# Environment Post Processors
org.springframework.boot.env.EnvironmentPostProcessor=\
org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor,\
org.springframework.boot.env.SpringApplicationJsonEnvironmentPostProcessor,\
org.springframework.boot.env.SystemEnvironmentPropertySourceEnvironmentPostProcessor

综上,SpringBoot是通过SpringFactoriesLoader的loadFactoryNames方法读取spring.factories文件的

你可能感兴趣的:(SpringBoot)