明明按照easyexcel官网导入最新版本的EasyExcel的maven坐标,代码也没报错。结果竟然报这个NoClassDefFoundError错误。
解决方法:
我原本是<dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>4.1.2</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>easyexcel</artifactId> <version>4.0.3</version> </dependency>
把easyexcel的依赖改成:(原因:easyexcel和poi版本不匹配)
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.3.4</version>
</dependency>
最后启示一下:
虽然是easyexcel官网快速入门文档说,直接添加最新版本的easyexcel,就行。实际并不行!!!
像这种要依靠着另一个依赖的依赖。就只能老实看版本表。不能想当然地用最新版本。就比如spring cloud alibaba 和 nacos有非常强的版本匹配的问题。我出错过,我能成功登录进去nacos后台,却一直发现不了微服务。后面把版本对齐后才解决了问题。
不要相信任何最新版本,每次导入jar包时候,看看这个jar包是不是有版本对应表
下面是追根溯源:
1.有一个博主从源码分析了:
【异常解决】Handler dispatch failed;nested exception is java.lang.NoClassDefFoundError: org/apache/common_handler dispatch failed; nested exception is java.-优快云博客https://blog.youkuaiyun.com/weixin_44299027/article/details/120077230我看了这个帖子,才猜想这个是不是版本问题。感谢这个博主。
2.easyexcel官网的QA答疑网站,贴了版本表。
必读 | Easy Excel 官网https://easyexcel.opensource.alibaba.com/qa/