netty在tomcat启动时加载问题

tomcat配置netty启动类

@Service
public class StartAddDataListener  implements ApplicationListener<ContextRefreshedEvent> {
    private Logger logger= LoggerFactory.getLogger(StartAddDataListener.class);
    @Autowired
    TCPServer  tcpServer;
    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        if(event.getApplicationContext().getParent() == null){
            logger.info("spring Start Success");
            NettyStartService nettyStartService=new NettyStartService();
            nettyStartService.setTcpServer(tcpServer);
            new Thread(nettyStartService).start();
        }
    }
}

这里判断一下Context 不然会启动两次导致netty端口被占用

你可能感兴趣的:(netty)