首页 > 其他分享 >spring-boot启动

spring-boot启动

时间:2024-08-11 21:38:42浏览次数:10  
标签:启动 spring boot applicationArguments listeners ex context new 上下文

public ConfigurableApplicationContext run(String... args) {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    //创建引导上下文
    DefaultBootstrapContext bootstrapContext = createBootstrapContext();
    ConfigurableApplicationContext context = null;
    configureHeadlessProperty();
    
    //生成启动监视器
    SpringApplicationRunListeners listeners = getRunListeners(args);
    
    //resources下创建META-INF/spring.factories文件
    //加载监听器如下方
    //org.springframework.boot.SpringApplicationRunListener=\
    //org.springframework.boot.context.event.EventPublishingRunListener
    listeners.starting(bootstrapContext, this.mainApplicationClass);
    try {
       //初始化应用参数类
       ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);
        
       //准备环境参数
       ConfigurableEnvironment environment = prepareEnvironment(listeners, bootstrapContext, applicationArguments);
       configureIgnoreBeanInfo(environment);
        
       //打印图像控制台
       Banner printedBanner = printBanner(environment);
        
       //创建spring上下文
       context = createApplicationContext();
       context.setApplicationStartup(this.applicationStartup);
        
       //准备上下文
       //完成事件ApplicationContextInitializedEvent
       //完成事件ApplicationPreparedEvent
       prepareContext(bootstrapContext, context, environment, listeners, applicationArguments, printedBanner);
        
       //刷新上下文
       //上下文刷新完成事件ContextRefreshedEvent
       //Web服务器完成事件WebServerlnitializedEvent
       refreshContext(context);
        
       afterRefresh(context, applicationArguments);
       stopWatch.stop();
       if (this.logStartupInfo) {
          new StartupInfoLogger(this.mainApplicationClass).logStarted(getApplicationLog(), stopWatch);
       }
       listeners.started(context);
       callRunners(context, applicationArguments);
    }
    catch (Throwable ex) {
       handleRunFailure(context, ex, listeners);
       throw new IllegalStateException(ex);
    }

    try {
       listeners.running(context);
    }
    catch (Throwable ex) {
       handleRunFailure(context, ex, null);
       throw new IllegalStateException(ex);
    }
    return context;
}

标签:启动,spring,boot,applicationArguments,listeners,ex,context,new,上下文
From: https://www.cnblogs.com/jichenghui/p/18353946

相关文章

  • SpringMVC - 初识
    1.简介SpringMVC是一个创建Web应用程序的框架,它是遵循Model-View-Controller的设计模式。SpringMVC通过DispatcherServlet来接收请求,然后对应对具体的controllers,models和views.2.一个HelloWorld事例1.添加maven依赖<dependency><groupId>org.springframework<......
  • SpringCloud天机学堂:我的课表(三)
    SpringCloud天机学堂:我的课表(三)文章目录SpringCloud天机学堂:我的课表(三)1、添加课程到课表2、分页查询课表3、查询正在学习的课程1、添加课程到课表首先,用户支付完成后,需要将购买的课程加入课表:而支付成功后,交易服务会基于MQ通知的方式,通知学习服务来执行加入......
  • Consider defining a bean of type ‘org.springframework.cloud.client.loadbalancer
    1、bug报错问题:项目启动失败***************************APPLICATIONFAILEDTOSTART***************************Description:Parameter1ofconstructorincom.tianji.learning.controller.InteractionQuestionAdminControllerrequiredabeanoftype'org......
  • spring使用validation参数及全局异常检测
    1.validation参数验证工具1.1.validation-api技术链validation-api是一个Java的数据校验规范,它定义了一套用于校验JavaBean的API。它是JSR303规范的一部分,也被称为BeanValidation。validation-api提供了一系列的注解,用于在Java类的字段、方法参数和方法返回值上添加校验规......
  • SpringBoot整合ElasticSearch
    文章目录SpringBoot整合ES实现ElasticsearchRepository使用ElasticsearchRestTemplate索引操作文档操作SpringBoot整合ES官方文档:https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#new-features.4-4-0版本选择Elasticsearch7.......
  • 基于Springboot+Vue的网上蛋糕销售系统(含源码数据库)
    1.开发环境开发系统:Windows10/11架构模式:MVC/前后端分离JDK版本:JavaJDK1.8开发工具:IDEA数据库版本:mysql5.7或8.0数据库可视化工具:navicat服务器:SpringBoot自带apachetomcat主要技术:Java,Springboot,mybatis,mysql,vue2.视频演示地址3.功能这个系......
  • 基于Springboot+Vue的学生就业信息系统 (含源码数据库)
    1.开发环境开发系统:Windows10/11架构模式:MVC/前后端分离JDK版本:JavaJDK1.8开发工具:IDEA数据库版本:mysql5.7或8.0数据库可视化工具:navicat服务器:SpringBoot自带apachetomcat主要技术:Java,Springboot,mybatis,mysql,vue2.视频演示地址3.功能在这个......
  • Windows ,elasticsearch 启动报错 failed to obtain node locks
    报错:2024.08.1118:14:45ERRORes[][o.e.b.ElasticsearchUncaughtExceptionHandler]uncaughtexceptioninthread[main]org.elasticsearch.bootstrap.StartupException:java.lang.IllegalStateException:failedtoobtainnodelocks,tried[[D:\soft\Java\sonarq......
  • SonarQube启动时,elasticsearch 报错 with lock id [0]; maybe these locations are n
     报错: 查看elasticsearch日志,在安装位置\sonarqube-9.9.6.92038\logs\es.log2024.08.1118:14:45ERRORes[][o.e.b.ElasticsearchUncaughtExceptionHandler]uncaughtexceptioninthread[main]org.elasticsearch.bootstrap.StartupException:java.lang.IllegalStateE......
  • Spring Cloud全解析:注册中心之Eureka服务获取和服务续约
    服务获取和服务续约eureka客户端通过定时任务的方式进行服务获取和服务续约,在com.netflix.discovery.DiscoveryClient类中,启动了两个定时任务来进行处理privatevoidinitScheduledTasks(){//是否需要拉取if(clientConfig.shouldFetchRegistry()){//......