项目启动设置监听事件

2019-12-20  本文已影响0人  thatbug
@Slf4j
@Configuration
public class StartEventListener {

    @Async
    @Order
    @EventListener(WebServerInitializedEvent.class)
    public void afterStart(WebServerInitializedEvent event) {
        Environment environment = event.getApplicationContext().getEnvironment();
        String appName = environment.getProperty("spring.application.name").toUpperCase();
        int port = event.getWebServer().getPort();
        String profile = StringUtils.arrayToCommaDelimitedString(environment.getActiveProfiles());
        log.info("---[{}]---启动完成,当前端口:[{}],环境变量[{}]---", appName, port, profile);
    }
}

@Slf4j lombok日志注解
@Configuration spring配置类
@Async异步执行,配合@EnableAsync使用
@Order spring执行顺序
@EventListener 事件监听
WebServerInitializedEvent web服务初始完成后事件

上一篇 下一篇

猜你喜欢

热点阅读