package com.cm.websocket.startup;

import com.cm.websocket.WebSocket;
import com.cm.websocket.manager.AppSocketSessionManager;
import com.cm.websocket.service.IMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: ApplicationStartUp
 * @Description: 应用启动
 * @Author: WangGeng
 * @Date: 2020/7/4 17:27
 * @Version: 1.0
 **/
@Component
public class WebSocketStartUp implements ApplicationRunner {

    @Autowired
    private IMessageService messageService;
    @Autowired
    private ApplicationContext applicationContext;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        AppSocketSessionManager.getInstance().setMessageService(messageService);
        WebSocket.setApplicationContext(applicationContext);
    }

}
