如何在项目中添加SpringBoot监听器

@Component
public class NettyBootstrap implements ApplicationListener<ContextRefreshedEvent> {

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        if(event.getApplicationContext().getParent() == null){
            try {
                //说明SpringApplication已经启动完毕
                WSServer.getInstance().start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

 

posted @ 2021-05-25 17:05  文所未闻  阅读(121)  评论(0编辑  收藏  举报