package com.genersoft.iot.vmp.netty.event;
|
|
import com.genersoft.iot.vmp.netty.config.SysConfig;
|
import com.genersoft.iot.vmp.netty.server.UdpServer;
|
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.event.ContextRefreshedEvent;
|
import org.springframework.stereotype.Component;
|
|
/**
|
* netty udp 服务启动监听
|
* @author zhongrj
|
* @date 2023-02-21
|
*/
|
@Component
|
public class StartupEvent implements ApplicationListener<ContextRefreshedEvent> {
|
|
private static ApplicationContext context;
|
|
@Override
|
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
|
try {
|
context = contextRefreshedEvent.getApplicationContext();
|
SysConfig sysConfig = (SysConfig) context.getBean(SysConfig.class);
|
//获取 udpServer
|
UdpServer udpServer = (UdpServer) StartupEvent.getBean(UdpServer.class);
|
//开启
|
udpServer.run(sysConfig.getUdpReceivePort());
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
public static Object getBean(Class beanName) {
|
return context != null ? context.getBean(beanName) : null;
|
}
|
}
|