Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getTestExecutionListeners() doesn't detect NoClassDefFoundError within BeanInstantiationException [SPR-11804] #16424

Closed
spring-projects-issues opened this issue May 19, 2014 · 5 comments
Assignees
Labels
in: test status: backported type: bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented May 19, 2014

Greg Allen opened SPR-11804 and commented

Related to #15971

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


Affects: 3.2.8, 4.0.3, 4.0.4

Issue Links:

  • #15971 Handle NoClassDefFoundError for TestExecutionListeners consistently in the TestContext framework

Referenced from: commits 1285467, f053ce5, 1120680, 2619955, 5e05a84, 41ed228, a2ef2c9

Backported to: 3.2.9

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented May 19, 2014

Juergen Hoeller commented

Fixed through detecting a NoClassDefFoundError cause within a BeanInstantiationException as well. This will be backported to 4.0.5 & 3.2.9.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented May 19, 2014

Juergen Hoeller commented

Greg, this change is available in the latest 4.0.5 snapshot already and will be available in the upcoming 3.2.9 snapshot in about 15 minutes. See http://projects.spring.io/spring-framework/ for Maven coordinates; would be great if you could give it a try!

Juergen

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented May 19, 2014

Sam Brannen commented

Thanks for picking that up so quickly, Juergen!

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented May 19, 2014

Juergen Hoeller commented

Np, Sam, was straightforward enough - and hopefully actually fixes the problem :-)

Greg, note that we'll be releasing Spring Framework 4.0.5 & 3.2.9 tomorrow European morning. It'd be great if you could give a snapshot a try before the release still.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented May 19, 2014

Greg Allen commented

Thanks Jeurgen. I can confirm the JUnit test now works under Eclipse using latest snapshot build of 4.0.5.

For the record, this originated from the article in today's Spring User's email: "Working with Spring Boot projects in STS made easy - part 2"

Of course the example will remain broken for now given spring-boot 1.0.2's dependencies. Hopefully google will bring anyone who experiences this issue to this page though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test status: backported type: bug
Projects
None yet
Development

No branches or pull requests

2 participants