springmvc 项目启动后自动运行方法
package com.jeeplus.modules.asr.config;
import com.jeeplus.common.config.Global;
import com.jeeplus.modules.asr.netty.server.UDPServer;
import com.jeeplus.modules.asr.netty.server.WebSocketServer;
import com.jeeplus.modules.asr.utils.AsrUtils;
import com.jeeplus.modules.whvoice.service.UDPVoiceServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
@WebListener
@Component
public class DefaultAsrServerConfig implements ServletContextListener {
private Logger log= LoggerFactory.getLogger(DefaultAsrServerConfig.class);
UDPServer udpServer=null;
WebSocketServer webSocketServer=null;
UDPVoiceServer udpVoiceServer=null;
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
log.info("初始化启动监听器");
//初始话udp server
new Thread(()->{
log.info("初始化启动udpServer");
//udpServer=new UDPServer(Integer.parseInt(Global.getConfig("serverport")));
//udpServer.start();
}).start();
//初始化websocket server
new Thread(()->{
log.info("初始化启动webSocketServer");
//int port=Integer.parseInt(Global.getConfig("wsport"));
//webSocketServer=new WebSocketServer();
//webSocketServer.setPort(port);
//webSocketServer.start();
}).start();
//初始化启动udpVoiceServer
new Thread(()->{
log.info("初始化启动udpVoiceServer");
String whVoicePath = Global.getConfig("whVoicePath");
udpVoiceServer=new UDPVoiceServer();
udpVoiceServer.start(whVoicePath);
}).start();
}
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
udpServer.close();
webSocketServer.close();
udpVoiceServer.close();
}
}