• springboot源码解读


    springboot源码从main函数开始

    public static void main(String[] args) {
        ApplicationContext app = SpringApplication.run(BeikbankApplication.class, args);
    }
    

    进入run方法,再持续进入到实际操作的步骤

    public static ConfigurableApplicationContext run(Object source, String... args) {
    	return run(new Object[] { source }, args);
    }
    
    public static ConfigurableApplicationContext run(Object[] sources, String[] args) {
    	return new SpringApplication(sources).run(args);
    }
    
    public ConfigurableApplicationContext run(String... args) {
        //秒表计时器,用来记录整个容器启动时间
    	StopWatch stopWatch = new StopWatch();
    	stopWatch.start();
    	ConfigurableApplicationContext context = null;
    	FailureAnalyzers analyzers = null;
    	//配置headless系统属性
    	configureHeadlessProperty();
    	//获取springbootApplication注解的类信息开启监听
    	SpringApplicationRunListeners listeners = getRunListeners(args);
    	listeners.starting();
    	try {
    	    //应用参数初始化
    		ApplicationArguments applicationArguments = new DefaultApplicationArguments(
    				args);
    		//环境变量初始化
    		ConfigurableEnvironment environment = prepareEnvironment(listeners,
    				applicationArguments);
    		//打印banner,就是spring图形
    		Banner printedBanner = printBanner(environment);
    		//创建应用上下文,默认会得到AnnotationConfigEmbeddedWebApplicationContext
    		context = createApplicationContext();
    		//反射加载实例化FailureAnalyzer实现类
    		analyzers = new FailureAnalyzers(context);
    		//上下文环境准备
    		prepareContext(context, environment, listeners, applicationArguments,
    				printedBanner);
    		//主要的IOC过程,也是springMVC的主要过程,进行bean的相关接口初始化和bean实例化
    		refreshContext(context);
    		//到上一步tomcat已经启动完成了,这里算是springboot的扩展接口,可以自己实现ApplicationRunner或CommandLineRunner接口,在这里进行实例化开始运行
    		afterRefresh(context, applicationArguments);
    		//发布事件监听器
    		listeners.finished(context, null);
    		//停止计时
    		stopWatch.stop();
    		if (this.logStartupInfo) {
    			new StartupInfoLogger(this.mainApplicationClass)
    					.logStarted(getApplicationLog(), stopWatch);
    		}
    		return context;
    	}
    	catch (Throwable ex) {
    		handleRunFailure(context, listeners, analyzers, ex);
    		throw new IllegalStateException(ex);
    	}
    }
    

    我把主要步骤的每一步都标明了注释,看起来这里很多都是springboot特有,但主要的实现还是对springMVC的继承,你去看springmvc的源码,会发现,它主要的过程就是refreshContext这个方法所展现的过程

  • 相关阅读:
    如何关闭和打开oracle 10g自动收集统计信息功能
    ORA00600:internal error code,arguments
    ORA01033: ORACLE initialization or shutdown in progress
    ORA01652:unable to extend temp segment by num in tablespace name
    ORA01578:Oracle data block corrupted
    ORA03113:endoffile on communication channel
    ORA01650:unable to extend rollback segment NAME by NUM intablespace NAME
    ORA01628:max # of extents num reached for rollback segment num
    C# 项目中的 bin 目录和 obj 目录的区别,以及 Debug 版本和 Release 版本的区别
    管理 Hadoop 集群的5大工具
  • 原文地址:https://www.cnblogs.com/sky-chen/p/9805470.html
Copyright © 2020-2023  润新知