类冲突引起异常:java.lang.NoClassDefFoundError: ch/qos/logback/classic/spi/ThrowableProxy

异常信息如下:

09-Dec-2019 19:31:04.058 INFO [cluster-ClusterId{value='5dee306dcb4f70060df2f0ff', description='null'}-192.168.10.61:27017] org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading Illegal access: this web application instance has been stopped already. Could not load [com.mongodb.internal.connection.LoggingCommandEventSender]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
 java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [com.mongodb.internal.connection.LoggingCommandEventSender]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
        at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1383)
        at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1371)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1224)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1186)
        at com.mongodb.internal.connection.InternalStreamConnection.createCommandEventSender(InternalStreamConnection.java:663)
        at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:245)
        at com.mongodb.internal.connection.CommandHelper.sendAndReceive(CommandHelper.java:83)
        at com.mongodb.internal.connection.CommandHelper.executeCommand(CommandHelper.java:38)
        at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:180)
        at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:124)
        at java.lang.Thread.run(Thread.java:748)

09-Dec-2019 19:31:04.060 INFO [cluster-ClusterId{value='5dee306dcb4f70060df2f0ff', description='null'}-192.168.10.61:27017] org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading Illegal access: this web application instance has been stopped already. Could not load [ch.qos.logback.classic.spi.ThrowableProxy]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
 java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [ch.qos.logback.classic.spi.ThrowableProxy]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
        at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1383)
        at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1371)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1224)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1186)
        at ch.qos.logback.classic.spi.LoggingEvent.(LoggingEvent.java:119)
        at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:419)
        at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:383)
        at ch.qos.logback.classic.Logger.info(Logger.java:595)
        at com.mongodb.diagnostics.logging.SLF4JLogger.info(SLF4JLogger.java:76)
        at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.logStateChange(DefaultServerMonitor.java:200)
        at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:151)
        at java.lang.Thread.run(Thread.java:748)

Exception in thread "cluster-ClusterId{value='5dee306dcb4f70060df2f0ff', description='null'}-192.168.10.61:27017" java.lang.NoClassDefFoundError: ch/qos/logback/classic/spi/ThrowableProxy
        at ch.qos.logback.classic.spi.LoggingEvent.(LoggingEvent.java:119)
        at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:419)
        at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:383)
        at ch.qos.logback.classic.Logger.warn(Logger.java:692)
        at com.mongodb.diagnostics.logging.SLF4JLogger.warn(SLF4JLogger.java:91)
        at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:155)
        at java.lang.Thread.run(Thread.java:748)
09-Dec-2019 19:31:05.736 INFO [mysql-cj-abandoned-connection-cleanup] org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading Illegal access: this web application instance has been stopped already. Could not load []. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
 java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load []. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
        at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1383)
        at org.apache.catalina.loader.WebappClassLoaderBase.getResource(WebappClassLoaderBase.java:1036)
        at com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.checkThreadContextClassLoader(AbandonedConnectionCleanupThread.java:117)
        at com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:84)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

 根据异常初步分析判断可能为jar包冲突引起的(logback-classic-*.jar),但是通过各种依赖分析及新包与老包(可正常启动的包)的对比,没有发现任何包冲突的常见迹象(如:不同模块依赖同一个jar包的不同版本、打进war包的jar包版本比开发工具内依赖的版本低等),于是无奈只能采用原始的方式-把新编写的代码从项目中移除,然后再逐步进行添加,每添加一部分就打包发布一次试试。最终问题定位到了新添加的过虑器上,该过虑器采用注解(@WebFilter(filterName = "encryptFilter", urlPatterns = {"/*"})的方式(其它过虑器都采用了bean注入的方式实现),然后把注解去掉就可以正常启动,一旦加上注解同样的异常就会出现,初步分析可能是WebFilter注解的jar包来自内嵌的tomcat-9.0.19,里面的代码引用了与较高版本logback-classic*.jar包,而服务器上部署的tomcat为9.0.16中没有对应的类,由于是在tomcat下运行,所以打包时内嵌的tomcat不会被打进war包中,然后就造成类的缺失。类冲突引起异常:java.lang.NoClassDefFoundError: ch/qos/logback/classic/spi/ThrowableProxy_第1张图片

PS:具体原因还有待分析,如果有哪位“基友”遇到相同的情况并完美解决,欢迎指导哈,谢谢喽。

最终方案只能将过虑器方案改回bean注入的形式,然后init方法的实现改为由构造方法去实现,麻烦了不少。

 

你可能感兴趣的:(异常,包冲突,未解决)