spring-core 3.2.9 + java 8

我们已经使用Spring 3.2.9将项目升级到Java8。一旦开始使用Java 8功能,Spring将不再启动(请参见下面的堆栈跟踪)。

我试图排除asm的旧用法,并包括以下依赖项:

<dependency>

<groupId>org.ow2.asm</groupId>

<artifactId>asm</artifactId>

<version>5.0.3</version>

</dependency>

<dependency>

<groupId>org.ow2.asm</groupId>

<artifactId>asm-util</artifactId>

<version>5.0.3</version>

</dependency>

<dependency>

<groupId>org.ow2.asm</groupId>

<artifactId>asm-commons</artifactId>

<version>5.0.3</version>

</dependency>

但是,它不能解决问题。有人知道如何解决这个问题吗?

不幸的是,我们无法升级到Spring 4,因为我们使用了一些依赖关系,这些依赖关系使升级过程非常耗时。

Offending resource: class path resource [xxxx/context-test.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [xxxxx.class]; nested exception is java.lang.IllegalArgumentException: INVOKESPECIAL/STATIC on interfaces require ASM 5

at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)

at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)

at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76)

at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:256)

at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:207)

at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:192)

at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139)

at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108)

at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)

at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)

at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)

at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)

at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)

at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)

at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)

at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)

at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)

at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)

at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)

at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)

at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)

... 23 more

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [xxxxxxxxxxxxx.class]; nested exception is java.lang.IllegalArgumentException: INVOKESPECIAL/STATIC on interfaces require ASM 5

at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:290)

at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:242)

at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:84)

at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73)

at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1438)

at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1428)

at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:195)

at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139)

at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108)

at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)

at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)

at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)

at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)

at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)

at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)

at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:250)

... 43 more

Caused by: java.lang.IllegalArgumentException: INVOKESPECIAL/STATIC on interfaces require ASM 5

at org.springframework.asm.MethodVisitor.visitMethodInsn(Unknown Source)

at org.springframework.asm.ClassReader.a(Unknown Source)

at org.springframework.asm.ClassReader.b(Unknown Source)

at org.springframework.asm.ClassReader.accept(Unknown Source)

at org.springframework.asm.ClassReader.accept(Unknown Source)

at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:64)

at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)

at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102)

at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:266)

... 58 more

回答:

你需要升级到Spring 4.x版本。

Spring 3.2.x将仅支持针对Java 7编译的Java 8运行时。你不能使用“静态接口”,因为这是Java 8的功能,并且无法针对Java 7进行编译。

这是一些Spring 4发行说明中的相关摘录,重点是它们:

与4.0 M1一起,我们发布了Spring Framework 3.2.3,其中包含针对最近报告的问题的修复程序,同时还包含OpenJDK 8运行时支持。Spring Framework 3.2.x将支持在JDK 8运行时上针对根据JDK 7(带有-target 1.7)或更早版本编译的应用程序进行部署。

然后,根据他们在spring.framework的build.gradle文件中的注释,他们将CGLib重新打包作为其发行版的一部分,并将ASM嵌入到项目中。

// As of Spring 4.0.3, spring-core includes asm 5.0 and repackages cglib 3.1, inlining

// both into the spring-core jar. cglib 3.1 itself depends on asm 4+, and is therefore

// further transformed by the JarJar task to depend on org.springframework.asm; this

// avoids including two different copies of asm unnecessarily.

这是4.0.3发行说明中的​​另一个相关部分,显示了它们如何嵌入其中的某些库以及Spring 4.0.3中所支持的内容。

我很高兴宣布Spring Framework 4.0.3可用。这是上周Java 8发布后框架的第一个版本。它现在是使用OpenJDK 8 GA构建的,并包括最新的ASM 5.0.1(在JDK 8 GA级别上也支持字节码,取代了我们先前使用的自定义ASM 4.2分支)。

以上是 spring-core 3.2.9 + java 8 的全部内容, 来源链接: utcz.com/qa/400731.html

回到顶部