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

Maven项目用POI 5.0.0导出DOCX为PDF报NoSuchMethodError如何解决

解决方案
  • 首先移除你手动添加的4.1.2版本poi-ooxml-schemas依赖,该版本与POI 5.0.0不兼容。POI 5.x系列已经弃用poi-ooxml-schemas,改用poi-ooxml-lite/poi-ooxml-full作为配套的schema实现。
  • 排查旧版本ooxml-schemas-1.4.jar的引入来源,在项目根目录执行以下命令打印完整依赖树,搜索ooxml-schemas即可定位到上层引入该包的依赖:
mvn dependency:tree -Dverbose
  • 对引入旧版ooxml-schemas的依赖添加排除规则,配置示例如下:
<dependency>
    <groupId>引入旧版包的依赖groupId</groupId>
    <artifactId>引入旧版包的依赖artifactId</artifactId>
    <version>对应版本号</version>
    <exclusions>
        <exclusion>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>ooxml-schemas</artifactId>
        </exclusion>
    </exclusions>
</dependency>
  • 添加POI 5.0.0配套的全量schema依赖,避免出现方法缺失问题:
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml-full</artifactId>
    <version>5.0.0</version>
</dependency>
  • 若需要全局强制锁定版本,防止其他传递依赖再次引入旧版包,可在父pom的dependencyManagement节点中添加对应依赖的版本声明,Maven会优先使用该节点中声明的版本:
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>5.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>5.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-full</artifactId>
            <version>5.0.0</version>
        </dependency>
    </dependencies>
</dependencyManagement>
  • 所有配置完成后执行mvn clean install重新构建项目,确认依赖加载正确即可解决该异常。

内容的提问来源于stack exchange,提问作者Marc Jordana Vilà

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.29 19:45:03