我有几个JUnit测试,都使用SpringJUnit4ClassRunner
运行。我可以通过我的SpringSource Tool Suite(Eclipse Juno)IDE单独运行它们,然后通过它们。如果我尝试按模块运行它们("在所选项目中运行所有测试" ),则它们会因以下NoClassDefFoundError
初始化错误而失败:
java.lang.NoClassDefFoundError: org/springframework/core/annotation/AnnotatedElementUtils at org.springframework.test.context.MetaAnnotationUtils$AnnotationDescriptor.(MetaAnnotationUtils.java:269) at org.springframework.test.context.MetaAnnotationUtils$AnnotationDescriptor.(MetaAnnotationUtils.java:257) at org.springframework.test.context.MetaAnnotationUtils$UntypedAnnotationDescriptor.(MetaAnnotationUtils.java:326) at org.springframework.test.context.MetaAnnotationUtils.findAnnotationDescriptorForTypes(MetaAnnotationUtils.java:171) at org.springframework.test.context.ContextLoaderUtils.buildMergedContextConfiguration(ContextLoaderUtils.java:621) at org.springframework.test.context.DefaultTestContext.(DefaultTestContext.java:93) at org.springframework.test.context.TestContextManager.(TestContextManager.java:119) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:120) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.(SpringJUnit4ClassRunner.java:109) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29) at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.(JUnit4TestReference.java:33) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.(JUnit4TestClassReference.java:25) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: java.lang.ClassNotFoundException: org.springframework.core.annotation.AnnotatedElementUtils at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) ... 27 more
任何想法如何解决?甚至排除故障。
吉文斯:
@RunWith(SpringJUnit4ClassRunner.class)
- 使用此跑步者的其他测试单独成功并作为组/套件@ContextConfiguration(classes = { MyModuleConfiguration.class })
@Autowired
中定义了@Bean
MyModuleConfiguration
。AnnotatedElementUtils
is a Spring 4 class,但我的依赖树显示没有Spring 4 任何。mvn test
成功。答案 0 :(得分:0)
我也面临同样的问题,但发现我使用的是依赖于spring 4依赖的spring数据版本。我降低了spring数据依赖的版本来解决这个问题。