You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用SpringBoot结合Apache POI 5.3.0读取.xlsx文件时出现NoSuchMethodError错误

SpringBoot结合Apache POI 5.3.0读取.xlsx文件时出现NoSuchMethodError错误

嘿,这个问题我熟得很!你遇到的NoSuchMethodError本质上就是依赖版本冲突搞出来的乱子。咱们来拆解下:

你看错误栈里明确说找不到org.apache.commons.io.input.BoundedInputStream$Builder org.apache.commons.io.input.BoundedInputStream.builder()这个方法——这个方法是Apache Commons IO在2.12.0版本才新增的,而Apache POI 5.3.0依赖的是更高版本的Commons IO(大概是2.13.0左右)。但你的项目里肯定是被其他依赖偷偷引入了更低版本的Commons IO,导致POI调用方法时找不到对应实现。

给你几个靠谱的解决办法:

  • 直接指定兼容的Commons IO版本
    在你的项目依赖文件里(Maven的pom.xml或者Gradle的build.gradle),明确声明Commons IO的版本,覆盖掉其他依赖带来的旧版本。比如:
    Maven写法:

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.13.0</version>
    </dependency>
    

    Gradle写法:

    implementation 'commons-io:commons-io:2.13.0'
    
  • 排查并排除冲突的依赖
    先搞清楚到底是哪个依赖引入了旧版本的Commons IO:

    • Maven执行命令:mvn dependency:tree
    • Gradle执行命令:gradle dependencies
      找到输出里commons-io的所有条目,看哪个依赖带了旧版本,然后在那个依赖里排除掉Commons IO的传递依赖。比如Maven里这么写:
    <dependency>
        <groupId>有问题的依赖groupId</groupId>
        <artifactId>有问题的依赖artifactId</artifactId>
        <version>对应版本号</version>
        <exclusions>
            <exclusion>
                <groupId>commons-io</groupId>
                <artifactId>commons-io</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    
  • 清理缓存重新构建
    有时候本地仓库里的依赖缓存可能有问题,执行清理命令重新下载依赖:

    • Maven:mvn clean install
    • Gradle:gradle clean build

另外如果你的项目用了Spring Boot的父依赖管理,也可以在dependencyManagement里提前锁定Commons IO的版本,确保所有依赖都用这个版本:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.13.0</version>
        </dependency>
    </dependencies>
</dependencyManagement>

备注:内容来源于stack exchange,提问作者prashanth

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.13 16:53:09