Spring Boot 启动类信息获取方式

获取 Spring Boot 启动类信息:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

@Component
public class StorageStartApplicationClassListener implements ApplicationListener<ApplicationStartedEvent> {
    @Override
    public void onApplicationEvent(ApplicationStartedEvent event) {
        Class<?> mainApplicationClass = event.getSpringApplication().getMainApplicationClass();
    }
}

上述示例使用 ApplicationStartedEvent 事件,也可以使用 ApplicationReadyEvent 事件。

如果本文对您有所帮助,欢迎打赏支持作者!

Licensed under CC BY-NC-SA 4.0
最后更新于 2024-02-27 09:59
使用 Hugo 构建
主题 StackJimmy 设计