java.lang.Object
org.miaixz.bus.spring.boot.SpringApplicationRunListener
- All Implemented Interfaces:
EventListener,org.springframework.boot.SpringApplicationRunListener,org.springframework.context.ApplicationListener<org.springframework.boot.context.event.ApplicationStartedEvent>,org.springframework.core.Ordered
public class SpringApplicationRunListener
extends Object
implements org.springframework.boot.SpringApplicationRunListener, org.springframework.context.ApplicationListener<org.springframework.boot.context.event.ApplicationStartedEvent>, org.springframework.core.Ordered
实现
SpringApplicationRunListener 和 ApplicationListener,计算启动阶段时间。
该类用于监控和记录Spring应用程序启动过程中的各个阶段耗时,支持动态加载和性能统计。 它记录JVM启动、环境准备、上下文初始化等关键阶段的性能指标,为应用程序启动性能分析提供数据支持。
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionSpringApplicationRunListener(org.springframework.boot.SpringApplication springApplication) 构造函数,初始化SpringApplicationRunListener -
Method Summary
Modifier and TypeMethodDescriptionvoidcontextLoaded(org.springframework.context.ConfigurableApplicationContext context) 应用程序上下文加载完成时的回调方法voidcontextPrepared(org.springframework.context.ConfigurableApplicationContext context) 应用程序上下文准备完成时的回调方法voidenvironmentPrepared(org.springframework.boot.ConfigurableBootstrapContext bootstrapContext, org.springframework.core.env.ConfigurableEnvironment environment) 环境准备完成时的回调方法intgetOrder()获取此监听器的顺序voidonApplicationEvent(org.springframework.boot.context.event.ApplicationStartedEvent event) 处理应用程序启动事件void应用程序启动完成时的回调方法voidstarting(org.springframework.boot.ConfigurableBootstrapContext bootstrapContext) 应用程序启动开始时的回调方法Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecutionMethods inherited from interface org.springframework.boot.SpringApplicationRunListener
failed, ready
-
Constructor Details
-
SpringApplicationRunListener
public SpringApplicationRunListener(org.springframework.boot.SpringApplication springApplication) 构造函数,初始化SpringApplicationRunListener- Parameters:
springApplication- Spring应用程序实例
-
-
Method Details
-
starting
public void starting(org.springframework.boot.ConfigurableBootstrapContext bootstrapContext) 应用程序启动开始时的回调方法记录JVM启动阶段的开始和结束时间,计算JVM启动耗时
- Specified by:
startingin interfaceorg.springframework.boot.SpringApplicationRunListener- Parameters:
bootstrapContext- 可配置的引导上下文
-
environmentPrepared
public void environmentPrepared(org.springframework.boot.ConfigurableBootstrapContext bootstrapContext, org.springframework.core.env.ConfigurableEnvironment environment) 环境准备完成时的回调方法记录环境准备阶段的开始和结束时间,计算环境准备耗时,并设置应用程序名称
- Specified by:
environmentPreparedin interfaceorg.springframework.boot.SpringApplicationRunListener- Parameters:
bootstrapContext- 可配置的引导上下文environment- 可配置的环境
-
contextPrepared
public void contextPrepared(org.springframework.context.ConfigurableApplicationContext context) 应用程序上下文准备完成时的回调方法记录应用程序上下文准备阶段的开始和结束时间,计算上下文准备耗时, 并添加SpringApplication中收集的初始化器统计信息
- Specified by:
contextPreparedin interfaceorg.springframework.boot.SpringApplicationRunListener- Parameters:
context- 可配置的应用程序上下文
-
contextLoaded
public void contextLoaded(org.springframework.context.ConfigurableApplicationContext context) 应用程序上下文加载完成时的回调方法记录应用程序上下文加载阶段的开始和结束时间,计算上下文加载耗时, 并注册启动报告器和生命周期处理器
- Specified by:
contextLoadedin interfaceorg.springframework.boot.SpringApplicationRunListener- Parameters:
context- 可配置的应用程序上下文
-
started
public void started(org.springframework.context.ConfigurableApplicationContext context, Duration timeTaken) 应用程序启动完成时的回调方法记录应用程序刷新阶段的开始和结束时间,计算刷新耗时, 添加所有阶段的统计信息到启动报告器,并标记应用程序启动完成
- Specified by:
startedin interfaceorg.springframework.boot.SpringApplicationRunListener- Parameters:
context- 可配置的应用程序上下文timeTaken- 启动所花费的时间
-
onApplicationEvent
public void onApplicationEvent(org.springframework.boot.context.event.ApplicationStartedEvent event) 处理应用程序启动事件当接收到ApplicationStartedEvent事件时调用此方法
- Specified by:
onApplicationEventin interfaceorg.springframework.context.ApplicationListener<org.springframework.boot.context.event.ApplicationStartedEvent>- Parameters:
event- 应用程序启动事件
-
getOrder
public int getOrder()获取此监听器的顺序- Specified by:
getOrderin interfaceorg.springframework.core.Ordered- Returns:
- 顺序值,值越小优先级越高
-