org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.test.context.transaction.TransactionalTestExecutionListener]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/transaction/annotation/AnnotationTransactionAttributeSource

Spring JIRA | Greg Allen | 3 years ago
tip
Do you find the tips below useful? Click on the to mark them and say thanks to rafael and Rafael Fischer Viola . Or join the community to write better ones.
  1. 0

    Related to https://jira.spring.io/browse/SPR-11347 run demo.ApplicationTests with an absolutely vanilla spring-boot-starter-parent 1.0.2 project (boot+web+test), when running the test from Eclipse JUnit runner. Java 1.7. thrown Exception is BeanInstantiationException, but catch block has catch NoClassDefFoundError Workaround is to add @TestExecutionListeners(DependencyInjectionTestExecutionListener.class) to ApplicationTests in org.springframework.test.context.TestContextManager.retrieveTestExecutionListeners(Class<?>) after 11:38:08.568 [main] DEBUG o.s.test.context.TestContextManager - @TestExecutionListeners is not present for class [class demo.ApplicationTests]: using defaults. org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.test.context.transaction.TransactionalTestExecutionListener]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/transaction/annotation/AnnotationTransactionAttributeSource at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:164) at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:105) at org.springframework.test.context.TestContextManager.retrieveTestExecutionListeners(TestContextManager.java:230) at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:120) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:120) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:109) 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: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.<init>(JUnit4TestReference.java:33) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(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.NoClassDefFoundError: org/springframework/transaction/annotation/AnnotationTransactionAttributeSource at org.springframework.test.context.transaction.TransactionalTestExecutionListener.<init>(TransactionalTestExecutionListener.java:108) 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.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148) ... 23 more Caused by: java.lang.ClassNotFoundException: org.springframework.transaction.annotation.AnnotationTransactionAttributeSource 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) ... 29 more

    Spring JIRA | 3 years ago | Greg Allen
    org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.test.context.transaction.TransactionalTestExecutionListener]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/transaction/annotation/AnnotationTransactionAttributeSource
  2. 0

    Related to https://jira.spring.io/browse/SPR-11347 run demo.ApplicationTests with an absolutely vanilla spring-boot-starter-parent 1.0.2 project (boot+web+test), when running the test from Eclipse JUnit runner. Java 1.7. thrown Exception is BeanInstantiationException, but catch block has catch NoClassDefFoundError Workaround is to add @TestExecutionListeners(DependencyInjectionTestExecutionListener.class) to ApplicationTests in org.springframework.test.context.TestContextManager.retrieveTestExecutionListeners(Class<?>) after 11:38:08.568 [main] DEBUG o.s.test.context.TestContextManager - @TestExecutionListeners is not present for class [class demo.ApplicationTests]: using defaults. org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.test.context.transaction.TransactionalTestExecutionListener]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/transaction/annotation/AnnotationTransactionAttributeSource at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:164) at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:105) at org.springframework.test.context.TestContextManager.retrieveTestExecutionListeners(TestContextManager.java:230) at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:120) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:120) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:109) 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: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.<init>(JUnit4TestReference.java:33) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(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.NoClassDefFoundError: org/springframework/transaction/annotation/AnnotationTransactionAttributeSource at org.springframework.test.context.transaction.TransactionalTestExecutionListener.<init>(TransactionalTestExecutionListener.java:108) 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.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148) ... 23 more Caused by: java.lang.ClassNotFoundException: org.springframework.transaction.annotation.AnnotationTransactionAttributeSource 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) ... 29 more

    Spring JIRA | 3 years ago | Greg Allen
    org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.test.context.transaction.TransactionalTestExecutionListener]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/transaction/annotation/AnnotationTransactionAttributeSource
  3. 0
    samebug tip
    This was caused by a failure to instantiate Kafka broker. Check your dependencies.
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0
    samebug tip
    This exception normally means you either have to add the said class to your dependencies or you miswrote it. Look in the documentation of your library how to add it as a dependency.
  6. 0
    samebug tip
    If you're using Hibernate, this indicates you're missing FasterXML Classmate dependency, which you can add with the following: <groupId>com.fasterxml</groupId> <artifactId>classmate</artifactId> <version>1.0</version>
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.lang.ClassNotFoundException

    org.springframework.transaction.annotation.AnnotationTransactionAttributeSource

    at java.net.URLClassLoader$1.run()
  2. Java RT
    ClassLoader.loadClass
    1. java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    2. java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    3. java.security.AccessController.doPrivileged(Native Method)
    4. java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    5. java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    6. sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    7. java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    7 frames
  3. Spring TestContext
    TransactionalTestExecutionListener.<init>
    1. org.springframework.test.context.transaction.TransactionalTestExecutionListener.<init>(TransactionalTestExecutionListener.java:108)
    1 frame
  4. Java RT
    Constructor.newInstance
    1. sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    2. sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    3. sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    4. java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    4 frames
  5. Spring Beans
    BeanUtils.instantiateClass
    1. org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
    2. org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:105)
    2 frames
  6. Spring TestContext
    SpringJUnit4ClassRunner.<init>
    1. org.springframework.test.context.TestContextManager.retrieveTestExecutionListeners(TestContextManager.java:230)
    2. org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:120)
    3. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:120)
    4. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:109)
    4 frames
  7. Java RT
    Constructor.newInstance
    1. sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    2. sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    3. sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    4. java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    4 frames
  8. JUnit
    ClassRequest.getRunner
    1. org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)
    2. org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)
    3. org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    4. org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    5. org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    6. org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
    6 frames
  9. JUnit4 Runner
    JUnit4TestLoader.loadTests
    1. org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
    2. org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
    3. org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
    4. org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
    4 frames
  10. JUnit3 Runner
    RemoteTestRunner.main
    1. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
    2. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    3. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    4. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
    4 frames