开机启动任务
<p>由于Nafos集成的springboot,自然兼容所有springboot的功能。
所以这里开机启动任务,我们列出其中一种写法(基于springboot的)。
run方法将在springboot容器启动之后立马执行。</p>
<pre><code class="language-java">@Component
public class StartTask implements ApplicationRunner {
@Autowired
ConfigService configService;
@Value("${im.server.id}")
private String serverId;
@Override
public void run(ApplicationArguments args) throws Exception {
//1)redis初始化
SpringApplicationContextHolder.getContext().getBean(RedisInit.class).initRedisPool();
//2) 加载game端注册的游戏
configService.loadConfigRegister();
//3) 启动rabbit监听
rabbitMqListener();
//4) 消息key记录
resetRedisKey();
}
}</code></pre>