3
votes

I have several JUnit tests, all run with SpringJUnit4ClassRunner. I can run them individually, by class, from my SpringSource Tool Suite (Eclipse Juno) IDE, and they pass. If I try to run them per-module ("Run all tests in the selected project"), then they fail with the following NoClassDefFoundError initialization error:

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

Any ideas how to resolve? Or even troubleshoot.

Givens:

  • JUnit Version 4.11
  • Spring Version 3.2.9-RELEASE
  • All tests use @RunWith(SpringJUnit4ClassRunner.class)--others using this runner succeed individually and as the group/suite
  • All tests use @ContextConfiguration(classes = { MyModuleConfiguration.class })
  • All tests have @Autowired @Beans defined in MyModuleConfiguration.
  • Maven Central says AnnotatedElementUtils is a Spring 4 class, but my dependency tree shows no Spring 4 anything.
  • This question is similar, and he looks to have been able to resolve the issue by changing some (unclear) versions.
  • [Update 1] mvn test on each module succeeds.
1
How about if you run maven from the command line? Maybe your IDE has another set of dependencies than the ones defined in maven.andrel
@andrel: Updated givens: mvn test (from command line) succeeds. I'll check my IDE runner's dependencies, tho, thx.JJ Zabkar

1 Answers

0
votes

I too faced the same problem but figured out that I was using a version of spring data which depended on spring 4 dependency. I lowered down the version of spring data dependency to resolve this issue.