?
1.現(xiàn)象描述
netty等一般放在程序啟動后再啟動,多以下面方式啟動:
@Component
@Order(value = 2)
public class NettyUdpServer implements ApplicationRunner {
如果在 Order 后面還有其它模塊被啟動,那么其它模塊就會被阻塞。
2.原因分析
主線程啟動netty后,netty會將主線程阻塞。因此,需要采用異步方式或使用線程池來啟動netty。
3.解決辦法
添加異步注解@Async
在NettyUdpServer的run中添加
@Async
@Override
public void run(ApplicationArguments args) throws Exception {
start();
}
異步注解的生效還需要在啟動類中激活:文章來源:http://www.zghlxwxcb.cn/news/detail-639513.html
@SpringBootApplication
@EnableAsync
public class SpringApplication { ... }
?文章來源地址http://www.zghlxwxcb.cn/news/detail-639513.html
到了這里,關(guān)于Springboot中整合netty啟動后,項目無法正常啟動?的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!