问题 : lang.NoClassDefFoundError: org/springframework/core/annotation/AnnotatedElementUtils,的解决方法

今天在做junit 测试的时候  出现了一个问题,花了一段时间 才解决。

java.lang.NoClassDefFoundError: org/springframework/core/annotation/AnnotatedElementUtils
at org.springframework.test.util.MetaAnnotationUtils$AnnotationDescriptor.<init>(MetaAnnotationUtils.java:289)
at org.springframework.test.util.MetaAnnotationUtils$UntypedAnnotationDescriptor.<init>(MetaAnnotationUtils.java:349)
at org.springframework.test.util.MetaAnnotationUtils$UntypedAnnotationDescriptor.<init>(MetaAnnotationUtils.java:344)
at org.springframework.test.util.MetaAnnotationUtils.findAnnotationDescriptorForTypes(MetaAnnotationUtils.java:191)
at org.springframework.test.util.MetaAnnotationUtils.findAnnotationDescriptorForTypes(MetaAnnotationUtils.java:166)
at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:271)
at org.springframework.test.context.DefaultTestContext.<init>(DefaultTestContext.java:67)
at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:103)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:124)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:115)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:33)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
Caused by: java.lang.ClassNotFoundException: org.springframework.core.annotation.AnnotatedElementUtils
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 24 more

这个问题是  因为找不到 springframework 的 一个类  AnnotatedElementUtils, 这个类 是因为 没有引入的pom  中,所以在编译的时候找不到,方法很简单,只需要在pom 文件中引入就可以了

<properties>    <spring.version>4.1.1.RELEASE</spring.version></properties>
<dependency>    <groupId>org.springframework</groupId>    <artifactId>spring-core</artifactId>    <version>${spring.version}</version></dependency>

这个依赖添加进去之后就解决问题了。

还有,在项目的lib  目录里面的  jar 包, 在试用mvn install的时候会报错 ,需要把这个jar  包传到  maven的 资源库,然后 在pom  中 添加依赖,这样才可以成功编译
时间: 2024-10-02 00:28:01

问题 : lang.NoClassDefFoundError: org/springframework/core/annotation/AnnotatedElementUtils,的解决方法的相关文章

spring Boot启动报错Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotatedElementUtils.getAnnotationAttributes

spring boot 启动报错如下 org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure

Maven Web项目 java.lang.NoClassDefFoundError: org/springframework/core/NestedRuntimeException错误

导读 使用Eclipse在从SVN或从git中check out Web项目后,运行可能会出现 java.lang.NoClassDefFoundError:org/springframework/core/NestedRuntimeException错误.检查Maven Dependencies后,发现org.springframework.core.NestedRuntimeException类就在Spring-core jar包里,系统怎么会没发现这个类呢?这时候就要考虑Maven Dep

[异常记录]java.lang.NoClassDefFoundError: org/springframework/core/env/EnvironmentCapab

使用Eclipse搭建springboot的过程中出现了这个问题: java.lang.NoClassDefFoundError: org/springframework/core/env/EnvironmentCapab 1.还是考虑 读取D:\JAVA\maven\repository\org\springframework\spring-core\5.0.4.RELEASE\spring-core-5.0.4.RELEASE.jar时出错; invalid LOC header (bad

java.lang.NoClassDefFoundError: org/springframework/core/ErrorCoded,分布式项目报错

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener java.lang.NoClassDefFoundError: org/springframework/core/ErrorCoded at java.lang.ClassLoader.defineClass1(Native Metho

缺jar包异常:java.lang.NoClassDefFoundError: org/springframework/core/convert/support/PropertyTypeDescriptor

严重: StandardWrapper.Throwable java.lang.NoClassDefFoundError: org/springframework/core/convert/support/PropertyTypeDescriptor at org.springframework.beans.PropertyAccessorFactory.forBeanPropertyAccess(PropertyAccessorFactory.java:37) at org.springfra

eclipse中部署web项目时报错java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener的解决方法

解决方案: 1.右键点击项目--选择Properties,选择Deployment Assembly,在右边点击Add按钮,在弹出的窗口中选择Java Build Path Entries 2.点击Next,选择Maven Dependencies 3.点击Finish,然后可以看到已经把Maven Dependencies添加到Web应用结构中了 操作完后,重新部署工程,不再报错了.然后我们再到.metadata\.plugins\org.eclipse.wst.server.core\tmp

使用Spring data Jpa 时遇到 java.lang.ClassNotFoundException: org.springframework.core.ReactiveTypeDescriptor

背景 原本项目是使用SSM+Maven进行开发,而后想同时使用Jpa(即mybatis和jpa混用),配置好相关文件后,使用Junit做测试时,出现以下错误. 主要: ERROR - Caught exception while allowing TestExecutionListener [org.springframewor[email protected]29774679] to prepare test instance [[email protected]]java.lang.Ille

java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext

***************************错误提示************************************************ SEVERE: A child container failed during start java.util.concurrent.ExecutionException:org.apache.catalina.LifecycleException: Failed to start component[StandardEngine[Cat

Caused by: java.lang.NoClassDefFoundError: org/springframework/web/context/WebApplicationContext

1.错误描述 严重: A child container failed during start java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/smp]] at java.util.concurre