SpringBoot源码分析之-启动流程分析三(监听器SpringApplicationRunListener)

SpringBoot运行流程源码分析:run方法流程及监听器 SpringBoot运行流程源码分析 上一章中我们分析了 SpringApplication 类实例化的源代码,在此过程中完成了基本配置文件的加载和实例化。当 SpringApplication 对象被创建之后, 通过调用其 run 方法来进行SpringBoot 的启动和运行,至此正式开启了 SpringApplication 的生命周期。 本章介绍的内容同样是 Spring Boot 运行的核心流程之一,我们将会围绕 SpringApplicationRunListeners、ApplicationA 阅读详情

前言

上一篇SpringBoot源码分析之-启动流程分析二(run方法)简单分析了的run流程
这一篇主要分析一下监听器 SpringApplicationRunListener

观察者模式

	class SpringApplicationRunListeners {
		//监听器集合
		private final List<SpringApplicationRunListener> listeners;
		SpringApplicationRunListeners(Log log, Collection<? extends SpringApplicationRunListener> listeners) {
			this.log = log;
			this.listeners = new ArrayList<>(listeners);
		}
		
		void starting() {
			for (SpringApplicationRunListener listener : this.listeners) {
				listener.starting();
			}
		}
		//其他方法差不多就是处理同的事件
		...
	}

	public interface SpringApplicationRunListener {
		default void starting() {}
		default void environmentPrepared(ConfigurableEnvironment environment) {}
		default void contextPrepared(ConfigurableApplicationContext context) {}
		default void contextLoaded(ConfigurableApplicationContext context) {}
		default void started(ConfigurableApplicationContext context) {}
		default void running(ConfigurableApplicationContext context) {}
		default void failed(ConfigurableApplicationContext context, Throwable exception) {}
	}
//---EventPublishingRunListener 方法对应的事件
starting: ApplicationStartingEvent
environmentPrepared: ApplicationEnvironmentPreparedEvent
contextPrepared: ApplicationContextInitializedEvent
contextLoaded: ApplicationPreparedEvent
started: ApplicationStartedEvent
running: ApplicationReadyEvent
failed: ApplicationFailedEvent

这个比较好看出是用了观察者模式
SpringApplicationRunListeners 中维护了SpringApplicationRunListener集合,
ApplicationEvent广播SpringApplicationRunListener处理相应的事件

run方法中出现的地方

		//获取监听器
		SpringApplicationRunListeners listeners = getRunListeners(args);
		//广播 ApplicationStartingEvent
		listeners.starting();
		//准备环境
		ConfigurableEnvironment environment = prepareEnvironment(listeners, applicationArguments);
		//准备上下文 
		prepareContext(context, environment, listeners, applicationArguments, printedBanner);
		//广播容器启动成功
		listeners.started(context);
		//广播容器运行
		listeners.running(context);
		//还有一个catch中的失败广播
		handleRunFailure(context, ex, exceptionReporters, listeners);

1.获取监听器

private SpringApplicationRunListeners getRunListeners(String[] args) {
		Class<?>[] types = new Class<?>[] { SpringApplication.class, String[].class };
		return new SpringApplicationRunListeners(logger,
				getSpringFactoriesInstances(SpringApplicationRunListener.class, types, this, args));
	}

getSpringFactoriesInstances方法之前分析过就是从类路径下的所有META-INF/spring.factories中去获取对应的实现类 ,这里是SpringApplicationRunListener对应实现类实例
这里目前一个实现类org.springframework.boot.context.event.EventPublishingRunListener

2. starting()

	void starting() {
		for (SpringApplicationRunListener listener : this.listeners) {
			listener.starting();
		}
	}
	
	@Override
	public void starting() {
		this.initialMulticaster.multicastEvent(new ApplicationStartingEvent(this.application, this.args));
	}

    //SimpleApplicationEventMulticaster
	@Override
	public void multicastEvent(ApplicationEvent event) {
		multicastEvent(event, resolveDefaultEventType(event));
	}

	@Override
	public void multicastEvent(final ApplicationEvent event, @Nullable ResolvableType eventType) {
		ResolvableType type = (eventType != null ? eventType : resolveDefaultEventType(event));
		//现在是null
		Executor executor = getTaskExecutor();
		//getApplicationListeners根据是否支持事件过滤SpringApplication设置的监听器
		for (ApplicationListener<?> listener : getApplicationListeners(event, type)) {
			if (executor != null) {
				executor.execute(() -> invokeListener(listener, event));
			}
			else {
				invokeListener(listener, event);
			}
		}
	}
	protected void invokeListener(ApplicationListener<?> listener, ApplicationEvent event) {
		//==null
		ErrorHandler errorHandler = getErrorHandler();
		if (errorHandler != null) {
			try {
				doInvokeListener(listener, event);
			}
			catch (Throwable err) {
				errorHandler.handleError(err);
			}
		}
		else {
			doInvokeListener(listener, event);
		}
	}
	
	private void doInvokeListener(ApplicationListener listener, ApplicationEvent event) {
		try {
			//对应的监听器执行方法
			listener.onApplicationEvent(event);
		}
	......
	}
listener.onApplicationEvent(event);就是对应监听器处理事件的方法

好了到此SpringApplicationRunListener处理事件大致流程分析清楚了.其他细节有兴趣可以看下.
下一篇准备分析 prepareEnvironment环境准备.

getApplicationListeners() 筛选出支持该事件的监听器监听器

//public abstract class AbstractApplicationEventMulticaster
//		implements ApplicationEventMulticaster, BeanClassLoaderAware, BeanFactoryAware {
protected Collection<ApplicationListener<?>> getApplicationListeners(
			ApplicationEvent event, ResolvableType eventType) {

		Object source = event.getSource();
		Class<?> sourceType = (source != null ? source.getClass() : null);
		ListenerCacheKey cacheKey = new ListenerCacheKey(eventType, sourceType);

		// Quick check for existing entry on ConcurrentHashMap...
		ListenerRetriever retriever = this.retrieverCache.get(cacheKey);
		if (retriever != null) {
			return retriever.getApplicationListeners();
		}

		if (this.beanClassLoader == null ||
				(ClassUtils.isCacheSafe(event.getClass(), this.beanClassLoader) &&
						(sourceType == null || ClassUtils.isCacheSafe(sourceType, this.beanClassLoader)))) {
			// Fully synchronized building and caching of a ListenerRetriever
			synchronized (this.retrievalMutex) {
				retriever = this.retrieverCache.get(cacheKey);
				if (retriever != null) {
					return retriever.getApplicationListeners();
				}
				retriever = new ListenerRetriever(true);
				//来看这行  筛选监听器逻辑
				Collection<ApplicationListener<?>> listeners =
						retrieveApplicationListeners(eventType, sourceType, retriever);
				this.retrieverCache.put(cacheKey, retriever);
				return listeners;
			}
		}
		else {
			// No ListenerRetriever caching -> no synchronization necessary
			return retrieveApplicationListeners(eventType, sourceType, null);
		}
	}


private Collection<ApplicationListener<?>> retrieveApplicationListeners(
			ResolvableType eventType, @Nullable Class<?> sourceType, @Nullable ListenerRetriever retriever) {

		List<ApplicationListener<?>> allListeners = new ArrayList<>();
		Set<ApplicationListener<?>> listeners;
		Set<String> listenerBeans;
		synchronized (this.retrievalMutex) {
			//初始化时设置的监听器集合
			listeners = new LinkedHashSet<>(this.defaultRetriever.applicationListeners);
			listenerBeans = new LinkedHashSet<>(this.defaultRetriever.applicationListenerBeans);
		}

		// Add programmatically registered listeners, including ones coming
		// from ApplicationListenerDetector (singleton beans and inner beans).
		for (ApplicationListener<?> listener : listeners) {
			if (supportsEvent(listener, eventType, sourceType)) {
				if (retriever != null) {
					retriever.applicationListeners.add(listener);
				}
				allListeners.add(listener);
			}
		}
.... //下面是有bean情况下的逻辑, 现在还没到容器初始化
	protected boolean supportsEvent(
			ApplicationListener<?> listener, ResolvableType eventType, @Nullable Class<?> sourceType) {

		GenericApplicationListener smartListener = (listener instanceof GenericApplicationListener ?
				(GenericApplicationListener) listener : new GenericApplicationListenerAdapter(listener));
		return (smartListener.supportsEventType(eventType) && smartListener.supportsSourceType(sourceType));
	}

这里有个适配器模式,还是比较好看出的
GenericApplicationListener 和 GenericApplicationListenerAdapter
如果监听器没有实现GenericApplicationListener 就创建一个GenericApplicationListenerAdapter适配器
主要supportsEventType 和 supportsSourceType两个方法确认监听器是否符合事件

//GenericApplicationListener接口
	boolean supportsEventType(ResolvableType eventType);

	/**
	 * Determine whether this listener actually supports the given source type.
	 * <p>The default implementation always returns {@code true}.
	 * @param sourceType the source type, or {@code null} if no source
	 */
	default boolean supportsSourceType(@Nullable Class<?> sourceType) {
		return true;
	}



//-----下面是GenericApplicationListenerAdapter类
	private final ApplicationListener<ApplicationEvent> delegate;
	@Nullable
	private final ResolvableType declaredEventType;
	
	public GenericApplicationListenerAdapter(ApplicationListener<?> delegate) {
		Assert.notNull(delegate, "Delegate listener must not be null");
		this.delegate = (ApplicationListener<ApplicationEvent>) delegate;
		this.declaredEventType = resolveDeclaredEventType(this.delegate);
	}
	
	@Override
	@SuppressWarnings("unchecked")
	public boolean supportsEventType(ResolvableType eventType) {
		if (this.delegate instanceof SmartApplicationListener) {
			Class<? extends ApplicationEvent> eventClass = (Class<? extends ApplicationEvent>) eventType.resolve();
			return (eventClass != null && ((SmartApplicationListener) this.delegate).supportsEventType(eventClass));
		}
		else {
			return (this.declaredEventType == null || this.declaredEventType.isAssignableFrom(eventType));
		}
	}

	@Override
	public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
		return supportsEventType(ResolvableType.forClass(eventType));
	}

根据是否支持事件类型和源来过滤出监听器
举个例子:LoggingApplicationListener

public class LoggingApplicationListener implements GenericApplicationListener {

	private static final Class<?>[] EVENT_TYPES = { ApplicationStartingEvent.class,
			ApplicationEnvironmentPreparedEvent.class, ApplicationPreparedEvent.class, ContextClosedEvent.class,
			ApplicationFailedEvent.class };
			
	private static final Class<?>[] SOURCE_TYPES = { SpringApplication.class, ApplicationContext.class };

	@Override
	public boolean supportsEventType(ResolvableType resolvableType) {
		return isAssignableFrom(resolvableType.getRawClass(), EVENT_TYPES);
	}

	@Override
	public boolean supportsSourceType(Class<?> sourceType) {
		return isAssignableFrom(sourceType, SOURCE_TYPES);
	}
}

可以看到LoggingApplicationListener 支持的类型EVENT_TYPES 和 源类型SOURCE_TYPES

所以根据事件类型和源过滤了获取了4个类
(第一篇构造SpringApplication中获取的监听器中过滤)

0 = {CloudFoundryVcapEnvironmentPostProcessor@1725} 
1 = {ConfigFileApplicationListener@1726} 
2 = {AnsiOutputApplicationListener@1727} 
3 = {LoggingApplicationListener@1728} 
4 = {ClasspathLoggingApplicationListener@1729} 
5 = {BackgroundPreinitializer@1730} 
6 = {DelegatingApplicationListener@1731} 
7 = {ParentContextCloserApplicationListener@1732} 
8 = {ClearCachesApplicationListener@1733} 
9 = {FileEncodingApplicationListener@1734} 
10 = {LiquibaseServiceLocatorApplicationListener@1735} 

//---

LoggingApplicationListener
BackgroundPreinitializer
DelegatingApplicationListener
LiquibaseServiceLocatorApplicationListener

**listener.onApplicationEvent(event);**监听器执行自己的方法了
这里就 LoggingApplicationListener 和 BackgroundPreinitializer 有对ApplicationStartingEvent事件类型的处理
LoggingApplicationListener 设置了日志系统 这里默认是Logback

Map<String, String> systems = new LinkedHashMap<>();
		systems.put("ch.qos.logback.core.Appender", "org.springframework.boot.logging.logback.LogbackLoggingSystem");
		systems.put("org.apache.logging.log4j.core.impl.Log4jContextFactory",
				"org.springframework.boot.logging.log4j2.Log4J2LoggingSystem");
		systems.put("java.util.logging.LogManager", "org.springframework.boot.logging.java.JavaLoggingSystem");
		SYSTEMS = Collections.unmodifiableMap(systems);

BackgroundPreinitializer 起了一个线程执行以下操作 一些工具的初始化
ApplicationReadyEvent 和 ApplicationFailedEvent 也就是后续的这两个事件会等他执行完

	public void onApplicationEvent(SpringApplicationEvent event) {
		if (!Boolean.getBoolean(IGNORE_BACKGROUNDPREINITIALIZER_PROPERTY_NAME)
				&& event instanceof ApplicationStartingEvent && multipleProcessors()
				&& preinitializationStarted.compareAndSet(false, true)) {
			performPreinitialization();
		}
		if ((event instanceof ApplicationReadyEvent || event instanceof ApplicationFailedEvent)
				&& preinitializationStarted.get()) {
			try {
				preinitializationComplete.await();
			}
			catch (InterruptedException ex) {
				Thread.currentThread().interrupt();
			}
		}
	}
	// performPreinitialization() 
	public void run() {
			runSafely(new ConversionServiceInitializer());
			runSafely(new ValidationInitializer());
			runSafely(new MessageConverterInitializer());
			runSafely(new JacksonInitializer());
			runSafely(new CharsetInitializer());
			preinitializationComplete.countDown();
		}
SpringBoot运行流程源码分析------阶段二(run方法核心流程) 在上面的代码中,实例化监听器需要有一个默认的构造方法,且构造方法的参数为Class 阅读详情

相关推荐

从IPv6到Tomcat:彻底解决127.0.0.1拒绝连接的完整指南

本文提供了从IPv6到Tomcat的全面指南,帮助开发者彻底解决127.0.0.1拒绝连接的问题。涵盖网络协议栈、服务配置、端口管理等多个层面的排查方法,特别针对Tomcat服务提供了专项解决方案,确保开发者能够快速定位并修复连接问题。

weixin_29207439的博客 471

SpringApplicationRunListener详解

文章目录SpringApplicationRunListenerde 作用再次源码分析方法详解具体使用注意事项 SpringApplicationRunListenerde 作用 命名我们就可以知道它是一个监听者,分析springboot启动流程我们会发现,它其实是用来在整个启动流程中接收不同执行点事件通知的监听者,SpringApplicationRunListener接口规定了SpringBoot的生命周期,在各个生命周期广播相应的事件,调用实际的ApplicationListener类。 再次源码分析

你就像甜甜的益达 1万+

BFD+OSPF+FRR:构建高可用网络的核心铁三角

摘要:VRRP、OSPF、BFD和FRR协同实现网络高可用。VRRP负责网关冗余,OSPF确保路由可达,BFD提供毫秒级故障检测,FRR实现快速路径切换。故障时,BFD立即检测并通知OSPF,FRR在OSPF收敛前切换流量,VRRP完成网关切换(如需)。BFD采用异步模式动态建立,效率最高。该机制确保业务流量无缝切换,提升网络可靠性。

A516988的博客 753

Spring Boot-8-SpringBoot特有监听器SpringApplicationRunListener

Spring Boot在启动的整个过程中会有一些逻辑需要处理,实现的方式的就是通过监听器。Spring设计监听器的方式比较简洁,这里的监听器和Servlet的ServletContextListener没有什么关系。org.springframework.boot.SpringApplicationRunListener 始自Spring Boot 1.0.0 org.springframework.boot.SpringApplication run方法的监听器。所有的SpringApplicationR

诗人不写诗 3466

ArcGIS基础:CAD数据转换为GIS数据(符号化显示、数据转换、线转面、空间连接)

1、符号化显示: CAD数据加载进来有很多列表,包含了点【point】、线【polyline】、面【polygon】、标注数据【Annotation】等数据,本次实验我们需要用到的是面数据,也就是.dwgPolygong格式的数据。如下图所示: 把数据加载进来,然后在2处打开属性表,查看CAD数据的属性表,打开后可以发现【layer】图层表示就是地块的用地性质,它就是符号化显示的依据。 我们在数据上右键【属性】,打开图层属性,找到【符号系统】,选择类别中的【唯一值】,然后在【值字段】下拉选择【layer】,

yuanYW7556的博客 2万+

保姆级教程:用Qlib和LightGBM从零搭建你的第一个AI量化选股策略(附完整代码)

本文提供了一份详细的教程,教你如何使用Qlib和LightGBM从零搭建AI量化选股策略。教程涵盖了环境配置、数据获取、特征工程、模型训练和策略回测等关键步骤,并附有完整代码和常见问题解决方案,适合量化投资初学者快速上手。

weixin_29191081的博客 445

SpringApplicationRunListener简单介绍

SpringApplicationRunListener 接口的作用主要就是在Spring Boot启动初始化的过程中可以通过SpringApplicationRunListener接口回调来让用户在启动的各个流程中可以加入自己的逻辑。 Spring Boot启动过程的关键事件(按照触发顺序)包括: 开始启动 Environment构建完成 ApplicationContext构建完成 ApplicationContext完成加载 ApplicationContext完成刷新并启动 启动完成 启动失败.

weixin_40705360的博客 1046

Ego-Planner实战避坑指南:从环境搭建到仿真运行

本文详细介绍了在Windows系统下,通过WSL2搭建Ego-Planner无人机路径规划算法开发环境的完整流程与实战避坑指南。内容涵盖ROS Noetic安装、第三方依赖库(如Ceres Solver)编译冲突解决、Realsense SDK版本降级处理,以及Gazebo仿真与真机调试的常见问题,旨在帮助开发者高效完成环境配置并成功运行仿真。

weixin_29232507的博客 699

【Spring Boot 源码学习】SpringApplication 的 run 方法监听器

本篇博文 Huazie 同大家一起深入分析了 SpringApplication 的 run 方法监听器,从配置的加载,接口定义,实现类等方面作了详细了解,最后通过自定义 SpringApplicationRunListener 接口实现并运行查看,进一步加深了理解。

Huazie 2050

从原理图到PCB:基于Allegro的8槽PXIe背板高速设计实战

本文详细介绍了基于Allegro软件进行8槽PXIe背板高速设计的完整实战流程。从理解规范、原理图设计、PCB布局规划,到高速PCIe差分对与精密时钟的布线艺术,再到电源与地处理以及最终的设计验证与生产文件输出,系统性地阐述了确保背板信号完整性、电源完整性和系统稳定性的关键技术与工程实践。

weixin_28312391的博客 203

7、RNA 二级结构预测:包含接吻发夹基序的新策略

本文提出三种用于预测RNA二级结构中接吻发夹基序的新策略,结合规范化规则与非歧义动态规划,分别在时间与空间复杂度之间进行权衡。策略A以O(n⁴)时间和O(n²)空间实现高效预测;策略B通过存储次优结果扩大搜索空间,空间复杂度升至O(n³);策略C全面探索组合可能,时间复杂度为O(n⁵),但保持O(n²)空间。实验表明不同策略适用于不同复杂度的序列,为RNA结构预测提供了灵活且可扩展的解决方案。

j7k8l的博客 132

SpringBoot启动监听SpringApplicationRunListener

命名我们就可以知道它是一个监听者,分析springboot启动流程我们会发现,它其实是用来在整个启动流程中接收不同执行点事件通知的监听者,SpringApplicationRunListener接口规定了SpringBoot的生命周期,在各个生命周期广播相应的事件,调用实际的ApplicationListener类。

程序缘 2142

18、探索隐私工程技术的前沿:从理论到实践

本文深入探讨了隐私工程技术的核心概念、关键技术及其应用场景,分析了加密技术、访问控制和用户界面设计等在隐私保护中的作用,并结合数据库保护、物联网设备等实际场景进行阐述。同时,文章还讨论了隐私工程技术面临的挑战与未来发展趋势,提出了数据最小化原则、差分隐私、隐私增强技术等优化策略以及隐私设计、隐私影响评估等最佳实践,最后展望了新兴技术对隐私保护的影响及法规推动下的发展方向。

weixin_35307279的博客 373

spring-boot启动源码分析(二)之SpringApplicationRunListener

在上一篇《》后,继续看了一个月的Spring boot启动源码,初步把流程看完了,接下来会不断输出总结,以巩固这段时间的学习。同时也希望能帮到同样感兴趣的同学。话不多说,进入正题环境介绍:spring boot版本:2.7.18主要starter:spring-boot-starter-webSpringApplication实例构造后,就开始调用它的run方法,开始启动spring boot。方法如下:本篇主要介绍上图中的4步,SpringApplicationRunListener会重点讲。

lft18的博客 1356

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

springboot启动-监听器模块

springboot启动-监听器模块监听器模块简介工作流程源码分析SpringApplicationRunListenersSpringApplicationRunListenerApplicationEventMulticasterApplicationListener设计总结经验总结扩展学习 监听器模块简介 springboot在启动过程中会调用监听器模块,将开始事件、环境准备事件、启动完成...

ignorewho的博客 1560

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

springboot 调用方法事物_SpringBoot 源码解析——SpringApplicationRunListener 源码分析

在 SpringApplication 源码分析 中分析 run 方法的时候,我们也分析了 SpringApplicationRunListener 的状态变换流程,这里就再来详细的分析一下该接口。SpringApplicationRunListener 定义SpringApplicationRunListener 接口的作用主要就是在 Spring Boot 启动初始化的过程中可以通过...

weixin_27215337的博客 198

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

springboot监听器_SpringBoot运行流程源码分析:run方法流程及监听器

SpringBoot运行流程源码分析上一章中我们分析了 SpringApplication 类实例化的源代码,在此过程中完成了基本配置文件的加载和实例化。当 SpringApplication 对象被创建之后, 通过调用其 run 方法来进行SpringBoot 的启动和运行,至此正式开启了 SpringApplication 的生命周期。本章介绍的内容同样是 Spring Boot 运行的核心流...

weixin_39707941的博客 194

Spring Boot 源码分析(二):SpringApplication和启动流程

文章主要对 Spring Boot 的源码进行分析,包括 SpringApplication 的创建和启动流程。介绍了 IOC 相关的 API 如 BeanFactory、ApplicationContext、Environment 等。在创建过程中,涉及判断应用类型、设置应用初始化器、事件监听器和确定主启动类。启动过程包括创建前准备、创建空容器、容器初始化、刷新容器、刷新后回调等步骤,并对每个步骤进行了详细阐述。

m0_59236433的博客 751

chapter8:SpringBoot启动配置原理

SpringBoot应用从主启动类启动后的运行流程主要包含下面几个要点:(1)准备环境执行ApplicationContextInitializer#initialize()方法;监听器SpringApplicationRunListener回调contextPrepared方法加载主配置类定义信息监听器SpringApplicationRunListener回调contextLoaded方法;(2)刷新启动IOC容器扫描加载所有容器中的组件;

学习技术的路上不断沉淀自己 1108

SpringBoot核心原理之事件和监听器(生命周期监听、事件触发、监听器、自定义事件发布和订阅)和配置类和Bean加载的时机

场景:监听应用从创建到销毁的整个生命周期。这样可以在应用启动之前,或启动之后做一些操作 用于事件发布。在生命周期的各个重要环节,都会将事件进行广播,如果我们对那个事件比较关系,可以继续监听自定义示例如下: MyAppListener.java src\main\resources\META-INF\spring.factories 启动springBoot应用,打印如下: 1.2 生命周期全流程 源码分析如下: 2. 事件触发时机 2.1 各种回调监听器 BootstrapRegistryInitiali

Bulut0907 2965

0501源码分析-启动过程-springboot2.7.x系列

0501源码分析-启动过程-springboot2.7.x系列

gaogzhen的博客 579

深入浅出:SpringBoot启动流程源码分析 (包含Spring IOC容器创建、自动配置时机、内置tomcat启动原理)

的值,这个值是一个全类名数组,这些类实现了 ApplicationContextInitializer 接口,用于在 ApplicationContext 初始化之前进行一些自定义的初始化操作。的值,这个值也是一个全类名数组,这些类实现了 ApplicationListener 接口,用于监听 Spring 应用上下文中的事件。它们也是需要自动装配的类。今天来深入底层讲一讲SpringBoot是如何启动的,也就是我们单击运行SpringBoot启动类,它底层发生了什么?Hello,大家好,我是此林。

2401_82540083的博客 1285

【源码】Springboot之事件管家SpringApplicationRunListeners事件管理机制源码分析

SpringApplicationRunListeners事件管理机制源码分析

万物皆字节 612

springboot 源码分析(启动过程)

15、发布应用上下文启动完成事件:触发所有SpringapplicationRunListener监听器的started事件方法。17、发布应用上下文就绪事件:触发所有springapplicationRunnListener将挺起的running事件方法。1、创建并启动计时监控类,可以看到记录当前任务的名称,默认是空字符串,然后记录当前springboot应用启动的开始时间。8、创建应用的上下文:根据不同哦那个的应用类型初始化不同的上下文应用类。4、创建所有spring运行监听器并发布应用启动事件。

yonghuliu的博客 311

springboot进阶(7):springboot监听机制

文章目录前言Java中的事件监听机制:Springboot监听机制通过案例学习Springboot监听机制小例子总结SpringApplicationRunListener 源码分析 前言 Srpingboot的监听,实际是对Java提供的事件监听机制的封装。 Java中的事件监听机制: 事件:Event,继承java.util.EventObject类的对象 事件源: Source,任何对象Object 监听器: Listener,实现java.util.EventListener接口的对象 Spri

不积跬步,无以至千里 814
上一篇: SpringBoot源码分析之-启动流程分析二(run方法步骤介绍)
下一篇: java基础-循环
卷心菜~
博客等级 码龄10年 2粉丝 12原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值