好吧,認可標題黨了,不管是jar包仍是war包都不影響繼承CommandLineRunner類中run方法的執行,可是在jar包下運行的好好的初始化容器後執行netty服務端綁定在war包下確實失效了。
現象,達成war包後,netty服務端綁定依然成功並可以正常監聽,可是發現全部web也沒都404了,一番偵查下覺得dispatchservlet沒有初始化,而後又懷疑是war包下 CommandLineRunner的run方法執行問題,遂把run方法中增長了sss輸出,把本來的netty服務端監聽綁定方法去掉了,果真ok了,。那麼爲何在jar包中這樣執行的好好的,在war包下就不能這麼作呢?百思不得其解,因此仔細對比了在war包下可以正常訪問web也沒與不能訪問之間的輸出內容(以下)
java
仔細對比,發現正常可以訪問的輸出中多了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方法中要執行的內容改爲異步的,沒想到果真好了。。。。。apache
@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(); // } }