SpringBoot 2.5.x 源码
2023-05-16 14:42:13 0 举报
spring 流程图
作者其他创作
大纲/内容
@Import(EurekaServerMarkerConfiguration.class)
是
listeners.running()
applicationContextFactory.create()
listeners.starting()
process @ComponentScan
registerResolvableDependency()
processCommonDefinitionAnnotations()
setResourceLoader()
getBean()
new ClassPathBeanDefinitionScaner()
ImportBeanDefinitionRegistrar.class
reader
process interfaces
refreshContext()
registerPostProcessor()
invokeBeanFactoryPostProcessor
super.postProcessBeanFactory()
collectImports()
postProcessAfterInitialization()
postProcessBeanFactory()
ApplicationContext.class
processImports()
继续往下走流程
preInstantiateSingletons()
@Component
postProcessApplicationContext()
getBeanFactory()
Lazy.classPrimary.classDependsOn.classRole.classDescription.class
afterRefresh()
DefaultEventListenerFactory.class
resolveBeforeInstantiation()
configEnvironment()
是否跳过解析
finishBeanFactoryInitialization()
createBootstrapContext()
new StandardServletEnvironment()
afterSingletonsInstantiated()
createBeanFatory()
new LoadTimeWeaverAwareProcessor()
getCondition()
deduceApplicationType
asSourceClass()
factoryId已注册
createBean()
@Import(AutoConfigurationPackages.Registrar.class)
invokeBeanDefinitionRegistryPostProcessors()
//...
deduceMainApplicationClass()
lazyInitialization
DelegatingApplicationContextInitializerSharedMetadataReaderFactoryContextInitializerContextIdApplicationContextInitializerConfigurationWarningApplicationContextInitializerRSocketPortInfoApplicationContextInitializerServerPortInfoApplicationContextInitializerConditionEvaluationReportLoggingListener
解析配置类Parse each @Configuration class
isConfigurationCandidate()
register Ordered
scanner.doScan()
conditionEvaluator.shouldSkip()
loadBeanDefinitions()
new ApplicationListenerDetector()
setInitializers()
parse @Bean
obtainFreshBeanFactory()
freezeConfiguration()
postProcessBeforeInstantiation()
Conditional类型注解
process @Bean
ConfigurationClassPostProcessor.java
有@Import注解
new ApplicationContextAwareProcessor()
@Configuration
@Import、@ImportResource
ApplicationEventPublisher.class
否
new BeanDefinitionLoader()
AutowiredAnnotationBeanPostProcessor.class
Resource.classPostConstruct.classPreDestroy.class
@SpringBootApplication
处理单例bean处理原型bean处理Scope Bean
listeners.environmentPrepared()
customizeBeanFatory()
onRefresh()
imports.addAll() 获取所有的import注解
componentScanParser.parse()
registerListeners()
getImports()
checkConfigurationClassCandidate()
loader.load()
parser.parse()
new AnnotationConfigServletWebServerApplicationContext()
registry.registerBeanDefinition()
registerImport() 递归解析import进来的类
registry.registerAlias()
addBeanPostProcessor()
Autowired.classValue.class
getListeners()
invokeBeanFactoryPostProcessors()
env.validRequiredProperties()
scanner.scan()
processPropertySource()
createWebServer()
configureAdditionalProfiles()
applyBeanPostProcessorsBeforeInstantiation()
request、session、application
筛选配置类
processSuperclass()
listeners.started()
new SpringApplication()
loadBeanDefinitionsFromRegistrars()
ServletWebServerApplicationContext
@EnableEurekaServer
refreshBeanFatory()
registerScope()
loadBeanDefinitionsForBeanMethod()
doProcessConfigurationClass()
ignoreDependencyInterface()
load()
processInterfaces()
new DefaultListableBeanFatory()
register()
initialize()
setClassloader()
registerAnnotationConfigProcessors()
processImportResource()
CommonAnnotationBeanPostProcessor.class
run()
finishRefresh()
initApplicationEventMulticaster()
processConfigurationClass()
ImportSelector.class
listeners.contextPrepared()
new ImportAwareBeanPostProcessor()
doGetBean()
EventListenerMethodProcessor.class
getOrCreateEnvironment()
new BeanPostProcessorChecker()
process @Import
addBeanPostProcessor(...)
ResourceLoader.class
condition.matches()
registerWebApplicationScopes()
process @Bean Method
internalCachingMetadataReaderFactory
printBanner()
@Component@ComponentScan@Import@ImportResource@Bean定义的方法
createBeanDefinitionLoader()
register PriorityOrdered
BootstrapApplicationListenerLoggingSystemShutdownListenerEnvironmentPostProcessorApplicationListenerAnsiOutputApplicationListenerLoggingApplicationListenerBackgroundPreinitializerRestartListenerDelegatingApplicationListenerParentContextCloserApplicationListenerClearCachesApplicationListenerFileEncodingApplicationListenerLiquibaseServiceLocatorApplicationListener
加载classpath下所有的 META-INF/spring.factories配置类
EventListener.class
bindToSpringApplication(env)
processConfigBeanDefinitions()
registerBeanDefinition()
applicationContext.refresh()
annotatedReader
prepareBeanFactory()
return
invokeBeanDefinitionRegistryPostProcessors
@ComponentScan
enhanceConfigurationClasses()
loadBeanDefinitionsFromImportedResources()
prepareRefresh()
configurePropertiesSources()
registerDependentBean()
setBootstraps()
includeFilters 过滤器中新增:Component.classjavax.annotation.ManagedBeanjavax.inject.Named
SharedMetadataReaderFactoryContextInitializer
registerBeanDefinitionForImportedConfigurationClass()
listeners.contextLoaded()
applyBeanPostProcessorsAfterInitialization()
configHeadlessProperty()
ConfigurationClassPostProcessor.class
configureIgnoreBeanInfo()
refresh()
doProcessCofigurationClass
initPropertySources()
initMessageSource()
postProcessBeanDefinitionRegistry()
configureConfigurationClassPostProcessor()
scanner
registerSingleton()
configureProfiles()
setListeners()
registerBeanPostProcessors()
reader.register()
setEnvironment()
reader.loadBeanDefinitaions()
register nonOrdered
prepareEnvironment()
检查配置类筛选出加了@Configuration 或 @Component注解的类
registerDefaultFilters()
@EnableAutoConfiguration
初始化bootstrappers
new WebApplicationContextServletContextAwareProcessor()
registerBean()
processPropertySoruce
processMemberClass()
解析配置类
new AnnotatedBeanDefinitionReader()
createApplicationContext()
addBeanFactoryPostProcessor()
@AutoConfigurationPackage
process @ImportResource
loadBeanDefinitionsForConfigurationClass()
applyInitializers()
processMemberClass
@Import(AutoConfigurationImportSelector.class)
Spring 5.xSpringBoot 2.5.x 源码
parser.validate()
...
getMergedLocalBeanDefinition()
multicastEvent()
doRegisterBean()
prepareContext()
初始化非懒加载的单例bean
收藏
0 条评论
下一页