21.09-SpringBoot2.x
2024-03-12 20:35:45 0 举报
SpringBoot2.x
作者其他创作
大纲/内容
getBanner()
defalut
listeners.started()
false
loader.load()
instanceof Class<?>
autoConfigurationEntry.getConfigurations()
REACTIVE
beanFactory.registerSingleton( \"springApplicationArguments\
PropertiesLoaderUtils .loadProperties(url)
configurePropertySources()
ApplicationListener
都没有设置
runners.addAll(context.getBeansOfType(ApplicationRunner.class).values()); runners.addAll(context.getBeansOfType(CommandLineRunner.class).values());
BeanUtils.instantiateClassAnnotationConfigReactiveWebServerApplicationContext
bannerPrinter = new SpringApplicationBannerPrinter()
banner.printBanner()
instanceof CharSequence
run(args)
instanceof Resource
Set<Object> sources= getAllSources()
environment = getOrCreateEnvironment()
listener.onAutoConfigurationImportEvent(event)
postProcessApplicationContext(context)
resourceLoader = new DefaultResourceLoader()
SpringApplication.run
实例化
autoConfigurationEntry= getAutoConfigurationEntry()
listeners.contextPrepared(context)
getSpringFactoriesLoaderFactoryClass()
循环
applyInitializers(context)
xmlReader.loadBeanDefinitions()
true
banners.addIfNotNull()
loadSpringFactories()
instanceClass = ClassUtils.forName()
invokeAwareMethods()
ConfigurationClassPostProcessor
new StandardServletEnvironment()
2021.07-spring启动源码分析
scanner = new ClassPathBeanDefinitionScanner(this)
this.annotatedReader = new AnnotatedBeanDefinitionReader(registry);
refresh()
this.webApplicationType
environment.getActiveProfiles()
selectImports()
SpringApplicationRunListener.class
fillProperties()
AutoConfigurationImportSelector.AutoConfigurationGroup.class
invokeBeanDefinitionRegistryPostProcessors
process
listeners.environmentPrepared(environment)
EnableAutoConfiguration.class
initializer.initialize(context)
AutoConfigurationMetadata
loadMetadata();
filter.match()
AbstractApplicationContext
doGetActiveProfiles()
SpringApplicationRunListeners listeners =getRunListeners(args);
font color=\"#0000ff\
autoConfigurationEntry
\"META-INF/spring-autoconfigure-metadata.properties\"
setInitializers()
urls=loadMetadata()
deferredImportSelectorHandler.process()
loadMetadata
reader =new AnnotatedBeanDefinitionReader(this)
refreshContext(context)
callRunner()
callRunners()
isComponent()
将启动时的类放入,此处也是解析各种自定义的注解的关键
default
new SpringApplication()
applicationArguments=new DefaultApplicationArguments(args)
new StandardEnvironment()
parse()
listeners= getAutoConfigurationImportListeners()
SpringFactoriesLoader .loadFactories(AutoConfigurationImportFilter.class)
解析字符串,尝试先class加载,然后作为resouce加载,然后作为Package加载
OnClassCondition
grouping.getImports()
EnableConfigurationPropertiesImportSelector
listeners.running(context)
getAutoConfigurationImportFilters()
result = new LinkedMultiValueMap<>();
SpringFactoriesLoader .loadFactoryNames(EnableAutoConfiguration.class)
setListeners()
new SpringApplicationRunListeners()
instanceClass.getDeclaredConstructor()
setActiveProfiles()
this.scanner.addExcludeFilter(new ClassExcludeFilter(sources));
new StandardReactiveWebEnvironment()
annotatedReader.register()
scanner.scan(source.getName())
SERVLET
banners=new Banners()
getImageBanner(environment)
context.getBeanFactory().setConversionService( ApplicationConversionService.getSharedInstance())
configureProfiles()
List<>
@AutoConfigurationPackage@Import(AutoConfigurationImportSelector.class)public @interface EnableAutoConfiguration {}
bindToSpringApplication()
构造
beanFactory.registerSingleton( \"springBootBanner\
new AutoConfigurationSorter()
Properties properties=PropertiesLoaderUtils.loadProperties()获取键值对后,放入到MultiValueMap
handler.processGroupImports()
afterRefresh()
instanceof Package
cache.get(classLoader)
BeanUtils.instantiateClass()
AutoConfigurationMetadataLoader .loadMetadata(this.beanClassLoader)
autoConfigurationMetadata
查找META-INF/spring.factories
.run()
banners.hasAtLeastOneBanner()
context.setEnvironment(environment)
this.xmlReader = new XmlBeanDefinitionReader(registry);
webApplicationType= WebApplicationType.deduceFromClasspath()
prepareContext()
fireAutoConfigurationImportEvents()
classLoader.getResources(path)
loader.setBeanNameGenerator()loader.setResourceLoader()loader.setEnvironment()
new PrintedBanner()
cache
put
getSpringFactoriesInstances()
getTextBanner(environment)
OnWebApplicationCondition
WebApplicationType.SERVLET
getAutoConfigurationEntry()
prepareEnvironment()
SpringBootExceptionReporter.class
configurations= getCandidateConfigurations()
@SpringBootConfiguration@font color=\"#4669ea\
BeanUtils.instantiateClassAnnotationConfigApplicationContext()
doRegisterBean()
new AutoConfigurationEntry()
ApplicationContextInitializer
sources.toArray(new Object[0])
load(context,sources)
propertySources =new MutablePropertySources()
getAutoConfigurationMetadata()
List<instance>
propertyResolver =new PropertySourcesPropertyResolver(propertySources)
BeanUtils.instantiateClassAnnotationConfigServletWebServerApplicationContext
instances=createSpringFactoriesInstances()
new PropertiesAutoConfigurationMetadata(properties)
registerBean()
bannerPrinter.print()
webApplicationType
context=createApplicationContext()
调用run方法
configureEnvironment()
listeners.starting()
OnBeanCondition
SpringBootBanner. printBanner()
new Properties()
spring.banner.location默认banner.txt
BeanDefinitionLoader loader = createBeanDefinitionLoader()
this.scanner = new ClassPathBeanDefinitionScanner(registry);
ApplicationConversionService.getSharedInstance()
getProperty(\"spring.profiles.active\")
MutablePropertySources sources = environment.getPropertySources()
new SpringBootBanner()
SpringFactoriesLoader .loadFactories(AutoConfigurationImportListener.class)
printBanner()
收藏
收藏
0 条评论
下一页