Module bus.starter

Class SpringBootConfigListener

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

    Fields
    Modifier and Type
    Field
    Description
    org.springframework.boot.SpringApplication
    SpringApplication 实例,用于传递给 BannerPrinter 以设置和获取 Banner。

    Fields inherited from interface org.springframework.core.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    定义监听器优先级,高于默认值以确保在环境准备阶段早期执行。
    void
    onApplicationEvent(org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent event)
    处理 ApplicationEnvironmentPreparedEvent 事件,初始化 SpringApplication 并触发配置注册。
    void
    registerConfigs(org.springframework.core.env.ConfigurableEnvironment environment)
    注册配置并触发 Banner 打印。

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.context.ApplicationListener

    supportsAsyncExecution
  • Field Details

    • application

      public org.springframework.boot.SpringApplication application
      SpringApplication 实例,用于传递给 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:
      onApplicationEvent in interface org.springframework.context.ApplicationListener<org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent>
      Parameters:
      event - 环境准备完成事件,包含 SpringApplication 和 ConfigurableEnvironment
    • getOrder

      public int getOrder()
      定义监听器优先级,高于默认值以确保在环境准备阶段早期执行。
      Specified by:
      getOrder in interface org.springframework.core.Ordered
      Returns:
      优先级值,HIGHEST_PRECEDENCE + 13
    • registerConfigs

      public void registerConfigs(org.springframework.core.env.ConfigurableEnvironment environment)
      注册配置并触发 Banner 打印。 调用 BannerPrinter 处理 Banner 打印逻辑,并执行其他配置注册。
      Parameters:
      environment - Spring 环境配置,用于 Banner 打印和配置注册