获取 Spring Boot 启动类信息: java 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 事件。
感谢您的耐心阅读!来选个表情,或者留个评论吧!