You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Spring Boot Test 3 NoClassDefFoundError: jakarta/servlet/ServletConnectionΒ #33661
Spring Boot Web + Jetty (exclude Tomcat) + MockMvc 3.0.1 and jakarta-servlet.version 5.0.0
Error test on startup:
java.lang.NoClassDefFoundError: jakarta/servlet/ServletConnection
at org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder.createServletRequest(MockHttpServletRequestBuilder.java:769)
at org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder.buildRequest(MockHttpServletRequestBuilder.java:663)
at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:172)
at org.example.ExampleControllerTest.test(ExampleControllerTest.java:29)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
Caused by: java.lang.ClassNotFoundException: jakarta.servlet.ServletConnection
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 74 more
Unfortunately at the time of release there was no Jetty version available that supported Servlet 6.0. We have an open issue to document how to downgrade dependencies. There's a lot of discussion in that issue with a few suggestions.
Jetty does not yet support Servlet 6.0. To use Jetty with Spring Boot 3.0, you will have to downgrade the Servlet API to 5.0. You can use the jakarta-servlet.version property to do so.
I need to set Servlet API to 5.0 when I'm using Spring Boot 3 with Jetty, and it works, but then Spring tests throw exception.
I've had the same issue, and the previously suggested options were not working for everything. Either the service would start or all the tests (inc mockmvc) would succeed. But not everything. :-(
Activity
kdebski85 commentedon Dec 31, 2022
Spring Boot 3 requires Jakarta 6, not 5.
Please see https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide#jakarta-ee
ServletConnectionwas added in Jakarta 6:https://jakarta.ee/specifications/platform/10/apidocs/jakarta/servlet/servletconnection
Since: Servlet 6.0philwebb commentedon Dec 31, 2022
Unfortunately at the time of release there was no Jetty version available that supported Servlet 6.0. We have an open issue to document how to downgrade dependencies. There's a lot of discussion in that issue with a few suggestions.
philwebb commentedon Dec 31, 2022
I think we can consider this one a duplicate of #33044
nibexo commentedon Jan 2, 2023
@kdebski85
Ok, but as this migration guide said:
I need to set Servlet API to 5.0 when I'm using Spring Boot 3 with Jetty, and it works, but then Spring tests throw exception.
bclozel commentedon Jan 2, 2023
@nibexo See #33044 (comment)
Tak1za commentedon Jan 12, 2023
Found a temporary fix for the problem.
Move back to Jakarta 6.0.0 and add the following dependency:
With the latest version of jetty-server.
With this the service starts up and the unit tests with MockMvc works as expected.
tasosz commentedon Mar 31, 2023
I've had the same issue, and the previously suggested options were not working for everything. Either the service would start or all the tests (inc mockmvc) would succeed. But not everything. :-(
In the end, this setup has worked for all:
plus:
nibexo commentedon Mar 31, 2023
@tasosz
Did you try set only
'org.eclipse.jetty:jetty-server:11.0.14' in implementation section?
hannah23280 commentedon Apr 12, 2023
Hi, I do not understand. I thought , Jetty does not support servlet 6. How would adding latest version able to fix the problem?
du-it commentedon Sep 7, 2023
#33044