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();
//    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章