由于项目久远,加上二开项目且业务复杂等方面原因。使用的poi版本比较老,一次项目漏洞扫描发现poi的jar的漏洞问题,于是升级项目的poi版本。
按照漏洞清单的建议升级了版本,太过于粗心大意的直接升级版本。此前并未有过相关升级的经验,直接导致没有按照官方给的建议升级版本所需要的jar包。
测试方面也过于简陋的测试,最终导致上线之后才发现问题。
升级前:
poi.jar(3.10-FINAL)
poi-ooxml.jar(3.10-FINAL)
poi-scratchpad.jar(3.10-FINAL)
poi-excelant.jar(3.10-FINAL)
org.apache.poi.xwpf.converter.core.jar(1.0.5)
org.apache.poi.xwpf.converter.xhtml.jar(1.0.5)
排除了:
curvesapi.jar
xmlbeans.jar
升级后:
org.apache.poi.xwpf.converter.core.jar(1.0.6)
org.apache.poi.xwpf.converter.xhtml.jar(1.0.6)
ooxml-schemas.jar(1.4)
poi.jar(5.2.1)
poi-ooxml.jar(5.2.1)
poi-scratchpad.jar(5.2.1)
poi-excelant.jar(5.2.1)
poi-ooxml-schemas.jar(4.1.2)
排除了:
curvesapi.jar
xmlbeans.jar
SparseBitSet.jar
poi-ooxml-lite.jar
commons-math3.jar
commons-collections4.jar
log4j-api.jar
此时回过头来看升级的jar发现ooxml-schemas.jar、poi-ooxml-schemas.jar完全是不用,但是当时测试的时候并未发现什么问题,并没有下载生成excel模板时的兼容性问题。
后续在修复版本升级带来的问题时,反复测试才发现ooxml-schemas.jar、poi-ooxml-schemas.jar和poi.5.2.1版本有类(ThemeDocument)冲突问题。
最终升级版本:
commons-codec-1.15.jar
commons-collections4-4.4.jar
commons-io-2.11.0.jar
commons-math3-3.6.1.jar
log4j-api-2.17.1.jar
SparseBitSet-1.2.jar
commons-compress-1.21.jar
commons-logging-1.2.jar
curvesapi-1.07.jar
slf4j-api-1.7.36.jar
xmlbeans-5.0.3.jar
poi-5.2.1.jar
poi-excelant-5.2.1.jar
poi-ooxml-5.2.1.jar
poi-ooxml-full-5.2.1.jar
poi-scratchpad-5.2.1.jar
pom引入:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-excelant</artifactId>
<version>5.2.1</version>
</dependency>
引入poi-excelant带入以下相关的jar,使用Maven Helper去掉重复的jar即可
ant(1.10.12)
poi-ooxml(5.2.1)
curvesapi(1.07)
commons-io(2.11.0)
commons-compress(1.21)
commons-collections4(4.4)
log4j-api(2.17.1)
poi(5.2.1)
SparseBitSet(1.2)
commons-codec(1.15)
commons-io(2.11.0)
commons-collections4(4.4)
log4j-api(2.17.1)
commons-math3(3.6.1)
poi-ooxml-lite(5.2.1)
xmlsec(2.3.0)
xmlbeans(5.0.3)
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-full</artifactId>
<version>5.2.1</version>
<exclusions>
<exclusion>
<artifactId>xmlbeans</artifactId>
<groupId>org.apache.xmlbeans</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>5.2.1</version>
<exclusions>
<exclusion>
<artifactId>log4j-api</artifactId>
<groupId>org.apache.logging.log4j</groupId>
</exclusion>
<exclusion>
<artifactId>commons-math3</artifactId>
<groupId>org.apache.commons</groupId>
</exclusion>
</exclusions>
</dependency>
这时候去官网找到5.2.1版本所需的jar包升级,又发现问题不能初始化类的问题(Could not initialize class org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument),
此时在代码里搜索才发现poi-ooxml-lite-5.2.1.jar和poi-ooxml-full-5.2.1.jar都有类ThemeDocument,去掉了poi-ooxml-lite-5.2.1.jar后正常。如果项目里引入了xbean-fixed会入xmlbeans冲突,
切记:遇到升级版本问题切勿百度搜索相关解决方案,直接官网找解决方案。
切记:遇到升级版本问题切勿百度搜索相关解决方案,直接官网找解决方案。
切记:遇到升级版本问题切勿百度搜索相关解决方案,直接官网找解决方案。