SpringMVC 异常信息ASM ClassReader failed to parse class file的问题解决

时间:2024-06-29 18:36:56

1.  环境信息:

Spring 3.2.0,  JDK 1.8.0

2.  运行简单的程序,出现以下错误信息:

2.  运行简单的程序,出现以下错误信息:

  1. Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [D:\NewWorkSpace\ep-user\target\test-classes\org\homework\ep\user\base\BaseTest.class]; nested exception is org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [D:\NewWorkSpace\ep-user\target\test-classes\org\homework\ep\user\base\BaseTest.class]; nested exception is java.lang.IllegalArgumentException
  2. at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:290)
  3. at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:242)
  4. at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:84)
  5. at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73)
  6. at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1438)
  7. at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1428)
  8. at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:185)
  9. at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139)
  10. at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108)
  11. at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
  12. at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
  13. at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
  14. at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
  15. at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
  16. at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
  17. at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
  18. at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
  19. at org.springframework.test.context.support.AbstractGenericContextLoader.loadBeanDefinitions(AbstractGenericContextLoader.java:233)
  20. at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:117)
  21. at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
  22. at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)
  23. at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:248)
  24. at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
  25. at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
  26. ... 25 more
  27. Caused by: org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [D:\NewWorkSpace\ep-user\target\test-classes\org\homework\ep\user\base\BaseTest.class]; nested exception is java.lang.IllegalArgumentException
  28. at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:56)
  29. at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
  30. at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102)
  31. at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:266)
  32. ... 48 more
  33. Caused by: java.lang.IllegalArgumentException
  34. at org.springframework.asm.ClassReader.<init>(Unknown Source)
  35. at org.springframework.asm.ClassReader.<init>(Unknown Source)
  36. at org.springframework.asm.ClassReader.<init>(Unknown Source)
  37. at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:53)
  38. ... 51 more

3. 问题分析

“ASM ClassReader failed to parse class file”是其中主要的原因。检查Maven的类库,没有发现问题,无asm显性依赖,其依赖产生于spring本身。故分析有可能是spring本身的 问题造成了;但是这么流行的spring,怎么会出错了,我不能这么牛x碰到这么简单的问题吧?

难道是版本?除了版本之外,spring无大区别。经过一般搜索,网上还真有类似的问题:

  1. Note that the Java 8 bytecode level (-target 1.8, as required by -source 1.8) is only fully supported as of Spring Framework 4.0.
  2. In particular, Spring 3.2 based applications need to be compiled with a maximum of Java 7 as the target,
  3. even if they happen to be deployed onto a Java 8 runtime. <span style="font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:#222222;font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 19.5px; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 249, 227);">Please upgrade to Spring 4 for Java 8 based applications.</span>

所以,看明白了吧,方案有两条:

a.  使用jdk7

b.  升级spring 4

4.  问题解决

最终选择了升级Spring4.1.7, 然后问题解决。