更新 Apache POI 4.0 后 - 属性 'http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit' 无法识别
after update Apache POI 4.0 - Property 'http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit' is not recognized
将 Apache POI 从 3.17 更新到 4.0.0 后,我上线了:
OPCPackage pck = OPCPackage.open(this.getTemplate());
一个例外:
java.lang.IllegalArgumentException: Property 'http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit' is not recognized.
at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.setAttribute(DocumentBuilderFactoryImpl.java:144)
at __redirected.__DocumentBuilderFactory.setAttribute(__DocumentBuilderFactory.java:125)
at org.apache.poi.ooxml.util.DocumentHelper.trySetXercesSecurityManager(DocumentHelper.java:143)
at org.apache.poi.ooxml.util.DocumentHelper.<clinit>(DocumentHelper.java:108)
at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:392)
at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.<init>(ContentTypeManager.java:104)
at org.apache.poi.openxml4j.opc.internal.ZipContentTypeManager.<init>(ZipContentTypeManager.java:54)
at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:258)
at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:725)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:275)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:181)
他们在 How to disable accessExternalDTD and entityExpansionLimit warnings with logback 中说我应该排除 xerces,但我已经有这个了:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.0</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
</exclusions>
</dependency>
我的设置:
- JDK 8
- 野蝇 14
回到 3.17 可以解决这个问题。
POI 4.0.0 代码适用于最新版本的 xerces - 该代码甚至没有尝试设置实体扩展限制,因为它将首先设置 xerces 安全管理器并在那里停止 -您可以尝试添加对最新版本 xerces 的显式依赖吗?
https://mvnrepository.com/artifact/xerces/xercesImpl/2.12.0
这已在 POI 4.0.1 中修复。
将 Apache POI 从 3.17 更新到 4.0.0 后,我上线了:
OPCPackage pck = OPCPackage.open(this.getTemplate());
一个例外:
java.lang.IllegalArgumentException: Property 'http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit' is not recognized.
at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.setAttribute(DocumentBuilderFactoryImpl.java:144)
at __redirected.__DocumentBuilderFactory.setAttribute(__DocumentBuilderFactory.java:125)
at org.apache.poi.ooxml.util.DocumentHelper.trySetXercesSecurityManager(DocumentHelper.java:143)
at org.apache.poi.ooxml.util.DocumentHelper.<clinit>(DocumentHelper.java:108)
at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:392)
at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.<init>(ContentTypeManager.java:104)
at org.apache.poi.openxml4j.opc.internal.ZipContentTypeManager.<init>(ZipContentTypeManager.java:54)
at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:258)
at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:725)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:275)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:181)
他们在 How to disable accessExternalDTD and entityExpansionLimit warnings with logback 中说我应该排除 xerces,但我已经有这个了:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.0</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
</exclusions>
</dependency>
我的设置:
- JDK 8
- 野蝇 14
回到 3.17 可以解决这个问题。
POI 4.0.0 代码适用于最新版本的 xerces - 该代码甚至没有尝试设置实体扩展限制,因为它将首先设置 xerces 安全管理器并在那里停止 -您可以尝试添加对最新版本 xerces 的显式依赖吗? https://mvnrepository.com/artifact/xerces/xercesImpl/2.12.0
这已在 POI 4.0.1 中修复。