美文网首页
项目启动设置监听事件

项目启动设置监听事件

作者: thatbug | 来源:发表于2019-12-20 17:13 被阅读0次
@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服务初始完成后事件

相关文章

网友评论

      本文标题:项目启动设置监听事件

      本文链接:https://www.haomeiwen.com/subject/ysuinctx.html