首页 > 编程语言 >springBoot源码(一)

springBoot源码(一)

时间:2024-04-26 11:48:15浏览次数:16  
标签:springBoot bootstrapContext startup applicationArguments listeners 源码 ex context

构造函数

运行代码

public ConfigurableApplicationContext run(String... args) {
		Startup startup = Startup.create();
		if (this.registerShutdownHook) {
			SpringApplication.shutdownHook.enableShutdownHookAddition();
		}
		DefaultBootstrapContext bootstrapContext = createBootstrapContext();
		ConfigurableApplicationContext context = null;
        //设置java.awt.headless的系统参数
		configureHeadlessProperty();
        //获取监听器
		SpringApplicationRunListeners listeners = getRunListeners(args);
		listeners.starting(bootstrapContext, this.mainApplicationClass);
		try {
			ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);
            //配置运行环境
			ConfigurableEnvironment environment = prepareEnvironment(listeners, bootstrapContext, applicationArguments);
			Banner printedBanner = printBanner(environment);
			context = createApplicationContext();
			context.setApplicationStartup(this.applicationStartup);
			prepareContext(bootstrapContext, context, environment, listeners, applicationArguments, printedBanner);
			refreshContext(context);
			afterRefresh(context, applicationArguments);
			startup.started();
			if (this.logStartupInfo) {
				new StartupInfoLogger(this.mainApplicationClass).logStarted(getApplicationLog(), startup);
			}
			listeners.started(context, startup.timeTakenToStarted());
			callRunners(context, applicationArguments);
		}
		catch (Throwable ex) {
			throw handleRunFailure(context, ex, listeners);
		}
		try {
			if (context.isRunning()) {
				listeners.ready(context, startup.ready());
			}
		}
		catch (Throwable ex) {
			throw handleRunFailure(context, ex, null);
		}
		return context;
	}

标签:springBoot,bootstrapContext,startup,applicationArguments,listeners,源码,ex,context
From: https://www.cnblogs.com/gushilcy/p/18159670

相关文章

  • SpringBoot整合AOP实现打印方法执行时间切面
    pom.xml<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-aop</artifactId></dependency>代码创建注解importjava.lang.annotation.ElementType;importja......
  • IDEA中springboot项目编译两次的问题
    原因:因为在导入项目的之后,项目无法运行,问题1:显示缺少org.springbootframe的依赖,不知道怎么解决,网上搜了个方法,就是勾选下图的选项,意思是把build操作由IDEA交给Maven,勾选之后确实可以启动项目了但是后面在执行Mybatis时,问题2:我发现无论如何都会报一个唯一键值重复的错误,思考原因......
  • Springboot版本升级
    升级简介开发软件:IDEA2019项目环境:java8,springboot2.0.5目标版本:java8,springboot2.5.5本文档前后变化对比,旧代码使用、//等表示。依赖升级升级版本<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <!......
  • springboot的日志swagger的配置
    我们导入swagger分为三步一.导入依赖首先我们需要在项目的pom里导入依赖<dependency><groupId>com.github.xiaoymin</groupId><artifactId>knife4j-spring-boot-starter</artifactId><version>3.0......
  • 利用SpringBoot的CommandLineRunner编写命令行jar程序
    1.项目pom<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.......
  • springboot中使用spring-javaformat-maven-plugin格式化代码插件
    在springboot项目中,想通过使用插件来统一项目中的代码,我这里选用的是spring-javaformat-maven-plugin。maven项目中,使用步骤如下:一、导入插件依赖pom.xml中添加<build><plugins><!--格式化代码插件--><plugin><groupId>i......
  • springboot+mybatisplus+dynicDatasource 从数据库表中查询数据源 动态添加
    1、pom依赖<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.12</version><relativePath/><!--lookuppa......
  • JDK源码分析-LinkedList
    概述相较于ArrayList,LinkedList在平时使用少一些。LinkedList内部是一个双向链表,并且实现了List接口和Deque接口,因此它也具有List的操作以及双端队列和栈的性质。双向链表的结构如下:它除了作为List使用,还可以作为队列或者栈来使用。publicclassLinkedList<E>......
  • springboot mybatis-plus dynamic-datasource实现
    基础架构是springboot+mybatis-plus实现动态数据源步骤步骤1:pom文件<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.12</version>......
  • SpringBoot项目添加2FA双因素身份认证
    什么是2FA(双因素身份验证)?双因素身份验证(2FA)是一种安全系统,要求用户提供两种不同的身份验证方式才能访问某个系统或服务。国内普遍做短信验证码这种的用的比较少,不过在国外的网站中使用双因素身份验证的还是很多的。用户通过使用验证器扫描二维码,就能在app上获取登录的动态口令,......