java.lang.Object
org.miaixz.bus.spring.listener.SpringBootConfigListener
- All Implemented Interfaces:
EventListener,org.springframework.context.ApplicationListener<org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent>,org.springframework.core.Ordered
public class SpringBootConfigListener
extends Object
implements org.springframework.context.ApplicationListener<org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent>, org.springframework.core.Ordered
监听
ApplicationEnvironmentPreparedEvent 事件,注册基于 ConfigurableEnvironment 的配置源, 并通过
BannerPrinter 处理 Spring Boot Banner 打印。 确保在环境准备阶段触发配置注册和 Banner 打印,且只执行一次。- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
FieldsModifier and TypeFieldDescriptionorg.springframework.boot.SpringApplicationSpringApplication 实例,用于传递给BannerPrinter以设置和获取 Banner。Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintgetOrder()定义监听器优先级,高于默认值以确保在环境准备阶段早期执行。voidonApplicationEvent(org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent event) 处理ApplicationEnvironmentPreparedEvent事件,初始化 SpringApplication 并触发配置注册。voidregisterConfigs(org.springframework.core.env.ConfigurableEnvironment environment) 注册配置并触发 Banner 打印。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
supportsAsyncExecution
-
Field Details
-
application
public org.springframework.boot.SpringApplication applicationSpringApplication 实例,用于传递给BannerPrinter以设置和获取 Banner。
-
-
Constructor Details
-
SpringBootConfigListener
public SpringBootConfigListener()
-
-
Method Details
-
onApplicationEvent
public void onApplicationEvent(org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent event) 处理ApplicationEnvironmentPreparedEvent事件,初始化 SpringApplication 并触发配置注册。 通过AtomicBoolean确保事件处理逻辑只执行一次。- Specified by:
onApplicationEventin interfaceorg.springframework.context.ApplicationListener<org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent>- Parameters:
event- 环境准备完成事件,包含 SpringApplication 和 ConfigurableEnvironment
-
getOrder
public int getOrder()定义监听器优先级,高于默认值以确保在环境准备阶段早期执行。- Specified by:
getOrderin interfaceorg.springframework.core.Ordered- Returns:
- 优先级值,HIGHEST_PRECEDENCE + 13
-
registerConfigs
public void registerConfigs(org.springframework.core.env.ConfigurableEnvironment environment) 注册配置并触发 Banner 打印。 调用BannerPrinter处理 Banner 打印逻辑,并执行其他配置注册。- Parameters:
environment- Spring 环境配置,用于 Banner 打印和配置注册
-