码迷,mamicode.com
首页 > 编程语言 > 详细

springboot的原理

时间:2019-07-18 12:03:37      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:class   public   object   nts   魔法   pac   nlog   lis   selector   

看下面一段代码,为什么一个@SpringBootApplication注解,就能够自动的执行N多的工作呢?

@EnableAsync
@SpringBootApplication
public class NimitzApplication {

    public static void main(String[] args) {
        new SpringApplicationBuilder(NimitzApplication.class).web(true).run(args);
    }
}

过程

  • 1 SpringApplication.run(Object source, String... args) 

  • 2 核心过程在ConfigurableApplicationContext run(String... args)

ApplicationArguments applicationArguments = new DefaultApplicationArguments(
                    args);
            ConfigurableEnvironment environment = prepareEnvironment(listeners,
                    applicationArguments);
            Banner printedBanner = printBanner(environment);
            context = createApplicationContext();
            analyzers = new FailureAnalyzers(context);
            prepareContext(context, environment, listeners, applicationArguments,
                    printedBanner);
            refreshContext(context);
            afterRefresh(context, applicationArguments);
            listeners.finished(context, null);
            stopWatch.stop();
            if (this.logStartupInfo) {
                new StartupInfoLogger(this.mainApplicationClass)
                        .logStarted(getApplicationLog(), stopWatch);
            }
            
  • 3 魔法过程 
SpringApplication.refreshContext 
->  AbstractApplicationContext.invokeBeanFactoryPostProcessors(ConfigurableListableBeanFactory beanFactory) 
-> PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors
-> ConfigurationClassPostProcessor.processConfigBeanDefinitions 
-> ConfigurationClassParser.parse 
-> ConfigurationClassParser.processConfigurationClass

// 最终 sourceClass是所有魔法的入口了
-> ConfigurationClassParser.doProcessConfigurationClass(configClass, sourceClass);

5 @import是最核心的注解,各种功能实际上是由三种类型的实现的
 @Configuration classes, ImportSelector and ImportBeanDefinitionRegistrar implementations

springboot的原理

标签:class   public   object   nts   魔法   pac   nlog   lis   selector   

原文地址:https://www.cnblogs.com/cffyh/p/11206342.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!