好吧,认可标题党了,不管是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(); // } }