springboot项目打war包CommandLineRunner引发的血案

好吧,承认标题党了,不论是jar包还是war包都不影响继承CommandLineRunner类中run方法的执行,但是在jar包下运行的好好的初始化容器后执行netty服务端绑定在war包下确实失效了。
现象,达成war包后,netty服务端绑定依然成功并能够正常监听,但是发现所有web也没都404了,一番侦查下以为dispatchservlet没有初始化,然后又怀疑是war包下 CommandLineRunner的run方法执行问题,遂把run方法中增加了sss输出,把原本的netty服务端监听绑定方法去掉了,果然ok了,。那么为什么在jar包中这样执行的好好的,在war包下就不能这么做呢?百思不得其解,所以仔细对比了在war包下能够正常访问web也没与不能访问之间的输出内容(如下)

仔细对比,发现正常能够访问的输出中多了

08-Aug-2019 15:29:13.904 淇℃伅 [RMI TCP Connection(5)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
[2019-08-08 03:29:13,961] Artifact yaojingcaiadmin.war: Artifact is deployed successfully

看上去是war包后,tomcat后面要执行的某些方法被阻塞了,所以怀疑是不是在初始化容器后调用CommandLineRunner的run方法(我这个run方法中执行的是netty服务端绑定)时间太久,所以造成后续的阻塞,使得后续方法无法执行。但是某些超时的异常又被tomact吃掉了(纯猜测,反正各种日志中没有看到异常),就抱着试一试的心理将run方法中要执行的内容改成异步的,没想到果然好了。。。。。

    @Component
    public class StartCommand implements CommandLineRunner {

    @Resource
    private NettyServerListener nettyServerListener;


    @Override
    public void run(String... args) throws Exception {
        System.out.println("sssss");
        CompletableFuture.runAsync(() -> nettyServerListener.start());
    }


//    @Override
//    public void run(ApplicationArguments args) throws Exception {
//        nettyServerListener.start();
//    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章