报错信息

cn.hutool.core.exceptions.DependencyException:You need to add dependency of 'poi-ooxml' to your project, and version >=4.12

在这里插入图片描述
再继续往下看报错信息,可看到有

caused by: java.lang.ClassNotFoundException: org.apache.commons.compress.utils.InputStreamStatistics

在这里插入图片描述

解决

打开hutool 官网,在hutool官网搜索报错信息,如下,即可搜到以下解决方案:点击即可打开

cn.hutool.core.exceptions.DependencyException:You need to add dependency of 'poi-ooxml' to your project, and version >=4.12

在这里插入图片描述

从hutool 官网 可见造成这个问题的3个原因:

部分用户使用POI模块时会提示:

You need to add dependency of 'poi-ooxml' to your project, and version >= 4.1.2

一般以下几个原因:

  1. 没有引入POI相关jar或引入版本太低
  2. 引入了多个版本的POI,导致包冲突了
  3. 没有引入关联依赖,这个具体要看下堆栈中的Cause By

结合我们项目排除了前两个原因,再看报错信息的

 caused by: java.lang.ClassNotFoundException: org.apache.commons.compress.utils.InputStreamStatistics

说明跟 org.apache.commons.compress 相关依赖有关:没有引入或者引入版本和 poi 不匹配。

我们项目之前commons-compress 引入版本为1.8.1,现在改为1.21 版本,poi 为4.1.2 版本 解决了这个问题。

最终修改为:

  <properties>
      <poi.version>4.1.2</poi.version>
  </properties>
  
 <dependencyManagement>
    <dependencies>
            <dependency>
                <groupId>org.apache.poi</groupId>
                <artifactId>poi-ooxml</artifactId>
                <version>${poi.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-compress</artifactId>
                <version>1.21</version>
            </dependency>
     </dependencies>
</dependencyManagement>

<dependencies>
       <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
        </dependency>
</dependencies>

小结

善于站在 "官网"的 “肩膀” 上解决问题。

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐