-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Handle NoClassDefFoundError for TestExecutionListeners consistently in the TestContext framework [SPR-11347] #15971
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
Comments
Juergen Hoeller commented Sam, can we maybe check for the presence of the Servlet API on the classpath there, and just register the ServletTestExecutionListener conditionally? Juergen |
Sam Brannen commented Gary Russell, can you please provide a stacktrace for one of those failing tests ASAP? I'd like to see where the in the code the Thanks, Sam |
Bruce Brouwer commented I just ran into this as well. Here is my stack trace (from using 4.0.1.BUILD-SNAPSHOT):
|
Sam Brannen commented Addressed as described in the comments for GitHub commit fb12e23 (4.0.1) and GitHub commit c1569d7 (3.2.7):
|
Sam Brannen commented Bruce Brouwer, thanks for providing the stack trace! Please give the change a try with the next snapshot and let us know if you still have issues. |
Bruce Brouwer commented It fixed my issue. Thanks. |
Sam Brannen commented
Great! Thanks for the feedback. |
Greg Allen commented Similar issue trying to 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 in org.springframework.test.context.TestContextManager.retrieveTestExecutionListeners(Class<?>) 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 |
Juergen Hoeller commented Greg, please turn this into a separate follow-up issue... We'll try to fix this for 4.0.5 and 3.2.9 still. Juergen |
Gary Russell opened SPR-11347 and commented
Background
Changes introduced in #15964 cause subclasses of abstract base test classes (i.e.
AbstractJUnit4SpringContextTests
andAbstractTestNGSpringContextTests
) in a non-web environment to fail withjava.lang.NoClassDefFoundError: javax/servlet/ServletContext
.There are a number of such test classes in Spring Integration that now break due to #15964.
Analysis
The fact that abstract base test classes pull in
ServletTestExecutionListener
is not problematic on its own (at least not with regard to the intended behavior of the TestContext framework's support for default listeners). Rather, the issue here is that aNoClassDefFoundError
is handled differently for implicit default listeners (i.e., listeners not declared via@TestExecutionListeners
) and listeners explicitly declared via@TestExecutionListeners
.The following code snippet from
TestContextManager.retrieveTestExecutionListeners()
represents the status quo.In the case of
AbstractJUnit4SpringContextTests
andAbstractTestNGSpringContextTests
, theServletTestExecutionListener
is explicitly declared via@TestExecutionListeners
as a convenience for the developer; however,ServletTestExecutionListener
is still considered a default from the perspective of the end user. The try-catch block inretrieveTestExecutionListeners()
should therefore be amended to work as intended for both implicit and explicit defaults.Deliverables
TestContextManager.retrieveTestExecutionListeners()
as follows:NoClassDefFoundError
.DEBUG
toINFO
.Affects: 4.0.1
Issue Links:
Referenced from: commits fb12e23, c1569d7
Backported to: 3.2.7
0 votes, 6 watchers
The text was updated successfully, but these errors were encountered: