记一次顽固eazyExcel异常排查
一开始报错 java.lang.NoSuchMethodError: org.apache.poi.ss.usermodel.Font.getIndex()I
这个错误是因为 POI 版本冲突导致的。NoSuchMethodError: org.apache.poi.ss.usermodel.Font.getIndex()I
表明 EasyExcel 使用的 POI 版本与您项目中现有的 POI 版本不兼容。
方案1:统一 POI 版本(推荐)
在 pom.xml 中显式指定 POI 版本,确保所有依赖使用相同版本:
xml
<properties><poi.version>5.2.3</poi.version><easyexcel.version>3.3.2</easyexcel.version>
</properties><dependencies><!-- EasyExcel --><dependency><groupId>com.alibaba</groupId><artifactId>easyexcel</artifactId><version>${easyexcel.version}</version><exclusions><exclusion><groupId>org.apache.poi</groupId><artifactId>poi</artifactId></exclusion><exclusion><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId></exclusion></exclusions></dependency><!-- 统一 POI 版本 --><dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>${poi.version}</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>${poi.version}</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml-schemas</artifactId><version>4.1.2</version></dependency>
</dependencies>
注意,到这里就是麻烦的开始
后来一直报错 java.lang.NoClassDefFoundError: org/apache/poi/logging/PoiLogManager
定位错误日志发现还有地方使用依赖 3.2.1 的版本,我明明指定了3.3.2
更新mvn依赖 mvn clean install -U
idea刷新 File → Invalidate Caches / Restart
都不管用,因为我把这个写在子模块了,有别的模块儿依赖了这个子模块,应该是有了强依赖
我把依赖和版本提到父模块。
删除仓库里 3.2.1的版本
查询 依赖版本是否一致: mvn dependency:tree -Dverbose | findstr easyexcel
发现都是3.2.2 了
启动项目,成功