java.lang.NoSuchMethodError:org.apache.poi.util.POILogger.log(I [Ljava / lang / Object;)V

使用apache poi依赖项时出现“跟随错误”。

org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: org.apache.poi.util.POILogger.log(I[Ljava/lang/Object;)V
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:982)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:634)

java.lang.NoSuchMethodError: org.apache.poi.util.POILogger.log(I[Ljava/lang/Object;)V
    org.apache.poi.openxml4j.opc.ZipPackage.saveImpl(ZipPackage.java:538)
    org.apache.poi.openxml4j.opc.OPCPackage.save(OPCPackage.java:1539)
    org.apache.poi.POIXMLDocument.write(POIXMLDocument.java:227)
    com.bonrix.common.test.Excel.sajan(Excel.java:62)


         <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi</artifactId>
      <version>3.15</version>
    </dependency>

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

  </dependencies> 

XSSFWorkbook工作簿=新的XSSFWorkbook();

    // Create a blank sheet 
    XSSFSheet sheet = workbook.createSheet("student Details"); 

    // This data needs to be written (Object[]) 
    Map<String, Object[]> data = new TreeMap<String, Object[]>(); 
    data.put("1", new Object[]{ "ID", "NAME", "LASTNAME" }); 
    data.put("2", new Object[]{ 1, "Pankaj", "Kumar" }); 
    data.put("3", new Object[]{ 2, "Prakashni", "Yadav" }); 
    data.put("4", new Object[]{ 3, "Ayan", "Mondal" }); 
    data.put("5", new Object[]{ 4, "Virat", "kohli" }); 

    // Iterate over data and write to sheet 
    Set<String> keyset = data.keySet(); 
    int rownum = 0; 
    for (String key : keyset) { 
        // this creates a new row in the sheet 
        Row row = sheet.createRow(rownum++); 
        Object[] objArr = data.get(key); 
        int cellnum = 0; 
        for (Object obj : objArr) { 
            // this line creates a cell in the next column of that row 
            Cell cell = row.createCell(cellnum++); 
            if (obj instanceof String) 
                cell.setCellValue((String)obj); 
            else if (obj instanceof Integer) 
                cell.setCellValue((Integer)obj); 
        } 
    } 
    try { 
        // this Writes the workbook gfgcontribute 
        FileOutputStream out = new FileOutputStream(new File("D://gfgcontribute.xlsx")); 
        workbook.write(out); 
        out.close(); 
        System.out.println("gfgcontribute.xlsx written successfully on disk."); 
    } 
    catch (Exception e) { 
        e.printStackTrace(); 
    } 

It's Work fine while running as java application but in web app Spring Controller it's shows error. I tried different version of poi. But Still its shows Error. I think it's conflict with other java which are added into my porm.xml file. I am using java spring for my project. I also referred https://stackoverflow.com/ from the solution, but any solution is not worked for me. in other project i used apache poi 3.5 which is working fine for me but in this case it's not working, is there any solution for this problem? Can i know what is the problem with my code or dependency which are used by me. i tried my best but i did not solved this error.

评论
  • 克制
    克制 回复

    Maven将所有依赖项下载到用户主目录中的文件夹.m2 / repository(即Windows上的C:\ users [您的用户名] .m2 \ repository)。当删除此文件夹时,Maven创建该文件夹并下载该依赖项。从那时起您要构建的项目采用正确的版本,该版本将在pom.xml中运行您的应用