你的位置:首页 > Java教程

[Java教程]Caused by: org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file


最近在琢磨maven,自己照着网上的例子塔了一个例子,在junit测试时报错了,详细错误信息:

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [D:\workspace\MAVEN\example_1\target\classes\cn\springmvc\service\impl\UserServiceImpl.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:\workspace\MAVEN\example_1\target\classes\cn\springmvc\service\impl\UserServiceImpl.class]; nested exception is java.lang.IllegalArgumentException  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.73)  at org.springframework.beans.factory.1438)  at org.springframework.beans.factory.1428)  at org.springframework.beans.factory.185)  at org.springframework.beans.factory.139)  at org.springframework.beans.factory.108)  at org.springframework.beans.factory.493)  at org.springframework.beans.factory.390)  at org.springframework.beans.factory.334)  at org.springframework.beans.factory.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.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)  at org.springframework.context.support.Abstract127)  at org.springframework.context.support.Abstract93)  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.context.support.ClassPath<init>(ClassPath)  at org.springframework.context.support.ClassPath<init>(ClassPath)  at cn.springmvc.test.UserTest.before(UserTest.java:17)  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)  at java.lang.reflect.Method.invoke(Unknown Source)  at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)  at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)  at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)  at org.junit.runners.ParentRunner.run(ParentRunner.java:309)  at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)  at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)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:\workspace\MAVEN\example_1\target\classes\cn\springmvc\service\impl\UserServiceImpl.class]; nested exception is java.lang.IllegalArgumentException  at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:56)  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)  ... 47 moreCaused by: java.lang.IllegalArgumentException  at org.springframework.asm.ClassReader.<init>(Unknown Source)  at org.springframework.asm.ClassReader.<init>(Unknown Source)  at org.springframework.asm.ClassReader.<init>(Unknown Source)  at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:53)  ... 50 more

一点点搜吧,万能的stackoverflow啊,哈哈,老外同仁给出的解释:

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. In particular, Spring 3.2 based applications need to be compiled with a maximum of Java 7 as the target, even if they happen to be deployed onto a Java 8 runtime. Please upgrade to Spring 4 for Java 8 based applications.

大概的意思就是java1.8版本只支持spring4.0以上,立马把pom里的sping版本换4.1.5就ok了,也可以把jdk调低点。