Hi, I'm using MockHttpServletRequest implementation from spring-test package in few our unit tests. Our project runs on Java 17 and uses Spring Boot 3.0.4, Spring 6.0.6 and Tomcat 10.1.5.

As stated for example here, Spring 6 should run with Jakarta EE 9 specifications which contains also Servlet API 5.0. However when I have Servlet API 5.0 on classpath and run our unit tests I'm getting this error pointing to MockHttpServletRequest constructor invocation:

jakarta/servlet/ServletConnection
java.lang.NoClassDefFoundError: jakarta/servlet/ServletConnection

Switching the Servlet API dependency to version 6.0 fixes the problem.

I'm afraid that I would probably need to use Servlet API in version 5.0 due to another dependency requirement so I would like know if this is bug in Spring Test project or I can fix it somehow on my side.

Thank you for your time, Petr H.

Comment From: bclozel

This behavior is expected and it's described in the upgrade guide:

The Spring-provided Servlet mocks (MockHttpServletRequest, MockHttpSession) require Servlet 6.0 now, due to a breaking change between the Servlet 5.0 and 6.0 API jars. They can be used for testing Servlet 5.0 based code but need to run against the Servlet 6.0 API (or newer) on the test classpath. Note that your production code may still compile against Servlet 5.0 and get integration-tested with Servlet 5.0 based containers; just mock-based tests need to run against the Servlet 6.0 API jar.

You'll need to amend your build to use Servlet 6.0 at least on your test classpath.