Application.java
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.crossoverjie.netty.action;
import com.crossoverjie.netty.action.server.HeartBeatServer;
import io.netty.channel.ChannelFuture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author crossoverJie
*/
@SpringBootApplication
public class Application implements CommandLineRunner{
private final static Logger LOGGER = LoggerFactory.getLogger(Application.class);
@Autowired
private HeartBeatServer heartBeatServer ;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
LOGGER.info("启动成功");
}
@Override
public void run(String... args) throws Exception {
ChannelFuture future = heartBeatServer.start();
Runtime.getRuntime().addShutdownHook(new Thread(){
@Override
public void run() {
heartBeatServer.destroy();
}
});
future.channel().closeFuture().syncUninterruptibly() ;
}
}