mavenapache-poitransitive-dependencyapache-poi-4apache-commons-compress

java.lang.NoSuchMethodError: 'org.apache.commons.compress.archivers.zip.ZipArchiveEntry org.apache.commons.compress.archivers.zip.ZipArchivelnputStrea


Exception while converting Multipart xlsx file into workbook.

ERROR - Entered Global Exception Handler. Exception occurred while processing the request: jakarta.servlet.ServletException:
Handler dispatch failed: java.lang.NoSuchMethodError: 'org.apache.commons.compress.archivers.zip.ZipArchiveEntry
org.apache.commons.compress.archivers.zip.ZipArchivelnputStream.getNextEntry0*
at
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1104)

Solution

  • This issue occurs due to a dependency conflict: both apache-poi and another library in your project bring in transitive dependencies on commons-compress, but each requires a different version.

    As a result, the version of commons-compress that gets resolved at runtime may not be compatible with all the libraries, leading to errors like:

    There are two ways to fix this issue.

    ✅ Option 1: Exclude the conflicting dependency Exclude the unwanted version from a specific dependency:

    <dependency>
      <groupId>some.group</groupId>
      <artifactId>some-artifact</artifactId>
      <exclusions>
        <exclusion>
          <groupId>org.apache.commons</groupId>
          <artifactId>commons-compress</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    

    ✅ Option 2: Force a specific version using dependencyManagement Use this when you want to enforce a version globally across all dependencies:

    <dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>org.apache.commons</groupId>
          <artifactId>commons-compress</artifactId>
          <version>1.21</version> <!-- or latest compatible version -->
        </dependency>
      </dependencies>
    </dependencyManagement>
    

    See how to fix maven dependency conflicts