代码改变世界

class org.springframework.core.type.classreading.ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class

2014-11-12 14:43  Rollen Holt  阅读(16855)  评论(0编辑  收藏  举报

今天在工作中遇到了下面的问题:

java.lang.IllegalStateException: Failed to load ApplicationContext
	at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99) ~[spring-test-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:101) ~[spring-test-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109) ~[spring-test-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75) ~[spring-test-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:331) ~[spring-test-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:213) [spring-test-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:290) [spring-test-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) [junit-4.10.jar:na]
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:292) [spring-test-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233) [spring-test-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87) [spring-test-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) [junit-4.10.jar:na]
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) [junit-4.10.jar:na]
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) [junit-4.10.jar:na]
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) [junit-4.10.jar:na]
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) [junit-4.10.jar:na]
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) [spring-test-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) [spring-test-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.junit.runners.ParentRunner.run(ParentRunner.java:300) [junit-4.10.jar:na]
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:176) [spring-test-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.junit.runner.JUnitCore.run(JUnitCore.java:157) [junit-4.10.jar:na]
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74) [junit-rt.jar:na]
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211) [junit-rt.jar:na]
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67) [junit-rt.jar:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_25]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_25]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_25]
	at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_25]
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) [idea_rt.jar:na]
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [D:\workspace\github\Timer\target\test-classes\com\rollenholt\timer\Demo.class]; nested exception is java.lang.IncompatibleClassChangeError: class org.springframework.core.type.classreading.ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class
	at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:301) ~[spring-context-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:242) ~[spring-context-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:85) ~[spring-context-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:74) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1424) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1414) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:187) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:141) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:110) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:508) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:251) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadBeanDefinitions(AbstractGenericContextLoader.java:253) ~[spring-test-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:122) ~[spring-test-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) ~[spring-test-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100) ~[spring-test-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:250) ~[spring-test-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64) ~[spring-test-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91) ~[spring-test-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	... 28 common frames omitted
Caused by: java.lang.IncompatibleClassChangeError: class org.springframework.core.type.classreading.ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class
	at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0_25]
	at java.lang.ClassLoader.defineClass(ClassLoader.java:760) ~[na:1.8.0_25]
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) ~[na:1.8.0_25]
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:455) ~[na:1.8.0_25]
	at java.net.URLClassLoader.access$100(URLClassLoader.java:73) ~[na:1.8.0_25]
	at java.net.URLClassLoader$1.run(URLClassLoader.java:367) ~[na:1.8.0_25]
	at java.net.URLClassLoader$1.run(URLClassLoader.java:361) ~[na:1.8.0_25]
	at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_25]
	at java.net.URLClassLoader.findClass(URLClassLoader.java:360) ~[na:1.8.0_25]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_25]
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) ~[na:1.8.0_25]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_25]
	at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0_25]
	at java.lang.ClassLoader.defineClass(ClassLoader.java:760) ~[na:1.8.0_25]
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) ~[na:1.8.0_25]
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:455) ~[na:1.8.0_25]
	at java.net.URLClassLoader.access$100(URLClassLoader.java:73) ~[na:1.8.0_25]
	at java.net.URLClassLoader$1.run(URLClassLoader.java:367) ~[na:1.8.0_25]
	at java.net.URLClassLoader$1.run(URLClassLoader.java:361) ~[na:1.8.0_25]
	at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_25]
	at java.net.URLClassLoader.findClass(URLClassLoader.java:360) ~[na:1.8.0_25]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_25]
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) ~[na:1.8.0_25]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_25]
	at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:63) ~[spring-core-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:82) ~[spring-core-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102) ~[spring-core-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:277) ~[spring-context-4.0.5.RELEASE.jar:4.0.5.RELEASE]
	... 51 common frames omitted

说实话根据这些异常信息一时半会还真没看出是什么原因引起的。Google后在Stackoverflow中发现了同样的问题.

链接地址:http://stackoverflow.com/questions/16209623/incompatibleclasschangeerror-class-classmetadatareadingvisitor-has-interface-cl

问题的原因是因为引入的Spring的版本不对。因为我引入的spring-core的版本是4.0.5.RELEASE,而引入的spring-asm的版本确为3.x的版本。因此版本不一致。

解决办法就是将两个的版本改为一致,我全部改为了4.0.5.RELEASE版本。然后问题解决了。