@PostConstruct()

public void init() {
//需要开启一个新的线程来执行netty server 服务器
new Thread(() -> {
try {
start();
} catch (InterruptedException e) {
e.printStackTrace();
}
}).start();
}

或者
public static void main(String[] args) {
SpringApplication.run(SxzdApplication.class, args);
run();
}

  1. private static NettyServer nettyServer = new NettyServer();
  2. private static void run(){<br /> Thread thread = new Thread(new Runnable() {<br /> @Override<br /> public void run() {<br /> nettyServer.run();<br /> }<br /> });<br /> thread.start();<br /> }