POI升级5.2.2报错问题
标签:版本冲突
报错信息
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.logging.log4j.Logger.atDebug()Lorg/apache/logging/log4j/LogBuilder;
at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.parseRelationshipsPart(PackageRelationshipCollection.java:309)
at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.<init>(PackageRelationshipCollection.java:160)
at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.<init>(PackageRelationshipCollection.java:130)
at org.apache.poi.openxml4j.opc.PackagePart.loadRelationships(PackagePart.java:565)
at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:745)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:315)
at org.apache.poi.ooxml.util.PackageHelper.open(PackageHelper.java:59)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:304)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:300)
at com.lxw.mutils.ExcelUtil.excel2List(ExcelUtil.java:59)
at com.lxw.mutils.ExcelUtil.excel2List(ExcelUtil.java:36)
at cn.enn.smart.controller.WorkbenchMonitorGuidelineController.main(WorkbenchMonitorGuidelineController.java:39)
错误代码
org.apache.poi.openxml4j.opc.PackageRelationshipCollection#parseRelationshipsPart,也就是错误信息中所提到的at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.parseRelationshipsPart(PackageRelationshipCollection.java:309)
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
private static final Logger LOG = LogManager.getLogger(PackageRelationshipCollection.class);
public void parseRelationshipsPart(PackagePart relPart){
...
LOG.atDebug().log("Parsing relationship: {}", relPart.getPartName());
...
}
只需要有2.17.1的log4j-api就可以,然而springboot中引入的是2.12.1
网上给出的方案
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>2.17.2</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>log4j-api</artifactId>
<groupId>org.apache.logging.log4j</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.2</version>
</dependency>
通过log4j-to-slf4j:2.17.2引入的是log4j-api:2.12.1,所以排除掉,单独引入log4j-api:2.17.2
为啥拍排除org.slf4j也没做解释
标签:5.2,java,poi,报错,POI,apache,org,log4j,PackageRelationshipCollection From: https://blog.csdn.net/weixin_41883161/article/details/136504624