在spring项目中使用发射框架 reflections 0.9.12 时,在windows上进行测试时候,不存在问题,但是发布部署到linux上进行运行测试,查看日志发现以下问题:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [x.x.x.SerializedTypeNameResolver]: Factory method 'serializedTypeNameResolver' threw exception; nested exception is java.lang.IllegalStateException: zip file closed
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:651) ~[spring-beans-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]
... 95 common frames omitted
Caused by: java.lang.IllegalStateException: zip file closed
at java.base/java.util.zip.ZipFile.ensureOpen(ZipFile.java:915) ~[na:na]
at java.base/java.util.zip.ZipFile.stream(ZipFile.java:647) ~[na:na]
at java.base/java.util.zip.ZipFile$1.stream(ZipFile.java:1131) ~[na:na]
at java.base/java.util.jar.JarFile.stream(JarFile.java:534) ~[na:na]
at org.reflections.vfs.ZipDir.lambda$getFiles$2(ZipDir.java:21) ~[reflections-0.9.12.jar!/:na]
at org.reflections.Reflections.scan(Reflections.java:260) ~[reflections-0.9.12.jar!/:na]
at org.reflections.Reflections.scan(Reflections.java:216) ~[reflections-0.9.12.jar!/:na]
at org.reflections.Reflections.<init>(Reflections.java:137) ~[reflections-0.9.12.jar!/:na]
at org.reflections.Reflections.<init>(Reflections.java:182) ~[reflections-0.9.12.jar!/:na]
at org.reflections.Reflections.<init>(Reflections.java:155) ~[reflections-0.9.12.jar!/:na]
at x.x.x.serializedTypeNameResolver.getTypesForName(SerializedTypeNameResolver.java:44) ~[integration-axondb-11.369.0.jar!/:11.369.0]
at x.x.x.serializedTypeNameResolver.<init>(GSerializedTypeNameResolver.java:23) ~[integration-axondb-11.369.0.jar!/:11.369.0]
at x.x.x.serializedTypeNameResolver(AxonServerSharedConfiguration.java:115) ~[integration-axondb-11.369.0.jar!/:11.369.0]
在github查找问题原因,发现反射框架0.9.12,在linux会存在bug,需要降级到0.9.11才能使用,降级后运行测试成功。
github参考地址:https://github.com/ronmamo/reflections/issues/279