Spring Boot启动流程
2021-10-28 14:27:22 24 举报
登录查看完整内容
Spring Boot启动流程
作者其他创作
大纲/内容
用于处理@Conditional注解
// Register bean processors that intercept bean creation. registerBeanPostProcessors(beanFactory);
执行ApplicationContextInitializer
this.annotatedReader = new AnnotatedBeanDefinitionReader(registry); this.xmlReader = (XML_ENABLED ? new XmlBeanDefinitionReader(registry) : null); this.groovyReader = (isGroovyPresent() ? new GroovyBeanDefinitionReader(registry) : null); this.scanner = new ClassPathBeanDefinitionScanner(registry); this.scanner.addExcludeFilter(new ClassExcludeFilter(sources));
注册ConfigurationClassPostProcessor注册RequiredAnnotationBeanPostProcessor注册AutowiredAnnotationBeanPostProcessor注册CommonAnnotationBeanPostProcessor注册PersistenceAnnotationBeanPostProcessor注册EventListenerMethodProcessor注册DefaultEventListenerFactory
1、加载BootstrapRegistryInitializer2、加载ApplicationContextInitializer3、加载ApplicationListener
AnnotationConfigServletWebServerApplicationContext. postProcessBeanFactory(beanFactory);
this.reader = new AnnotatedBeanDefinitionReader(this); this.scanner = new ClassPathBeanDefinitionScanner(this);
refresh()
加载SpringApplicationRunListener
AnnotationConfigUtils.registerAnnotationConfigProcessors(this.registry);
if (this.basePackages != null && this.basePackages.length > 0) { this.scanner.scan(this.basePackages);} if (!this.annotatedClasses.isEmpty()) { this.reader.register(ClassUtils.toClassArray(this.annotatedClasses)); }
// Prepare this context for refreshing.\t\t\tprepareRefresh();
// Invoke factory processors registered as beans in the context.\t\t\t\tinvokeBeanFactoryPostProcessors(beanFactory);
ServletWebServerApplicationContext.createWebServer()
obtainFreshBeanFactory()
// Instantiate all remaining (non-lazy-init) singletons.\t\t\t\tfinishBeanFactoryInitialization(beanFactory);
创建ApplicationServletEnvironment
this.scanner.clearCache();\t\tsuper.prepareRefresh();
// Prepare the bean factory for use in this context.\t\t\tprepareBeanFactory(beanFactory);
// Initialize other special beans in specific context subclasses.\t\t\t\tonRefresh();
加载EventPublishingRunListener
// Allows post-processing of the bean factory in context subclasses. postProcessBeanFactory(beanFactory);
开始
执行BootstrapRegistryInitializer
AnnotatedBeanDefinitionReader#register(source)
加载spring.factories
Spring容器加载Bean定义信息的两个扫描器:AnnotatedBeanDefinitionReader:读取注解声明的bean的定义信息ClassPathBeanDefinitionScanner:读取xml声明的bean的定义信息
beanFactory.addBeanPostProcessor(new WebApplicationContextServletContextAwareProcessor(this)); beanFactory.ignoreDependencyInterface(ServletContextAware.class); registerWebApplicationScopes();
直接获取
注册demoApplication
printBanner(environment)
new AnnotationConfigServletWebServerApplicationContext()
AnnotationConfigServletWebServerApplicationContext.prepareRefresh()
createApplicationContext()
0 条评论
回复 删除
下一页