java.lang.NoSuchMethodError: org.springframework.core.type.AnnotationMetadata.introspect(Ljava/l

异常代码


 java.lang.NoSuchMethodError:
    org.springframework.core.type.AnnotationMetadata.introspect(Ljava/lang/Class;)Lorg/springframework/core/type/AnnotationMetadata;
    
    	at
    org.springframework.context.annotation.ConfigurationClassUtils.checkConfigurationClassCandidate(ConfigurationClassUtils.java:108)
    	at
    org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:276)
    	at
    org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236)
    	at
    org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
    	at
    org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)
    	at
    org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706)
    	at
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
    	at
    org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
    	at
    org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
    	at StudentTest2.test1(StudentTest2.java:17) 	at
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 	at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:498) 	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.InvokeMethod.evaluate(InvokeMethod.java:17)
    	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.junit.runner.JUnitCore.run(JUnitCore.java:160) 	at
    com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    	at
    com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    	at
    com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    	at
    com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

这个问题困扰了我好几个小时,我把整个项目都冲头到尾检查了一遍,都没找到问题,甚至打开我昨天都能运行的项目,结构原来那个也是这样的问题,后来在网上找了好几篇,终于看到了一篇有用的。具体原因就是我的几个spring依赖版本不同,

异常原因

pom.xml中添加的依赖版本不兼容导致。

解决办法

将与spring相关的几个配置文件全部统一版本,我这里用的是5.2.3版本。另外说明一点junit测试版本建议4.12以上,4.11也可以。

顺便附上我常用的依赖。
常用依赖

你可能感兴趣的:(异常)