Skip to content

Dependency on Servlet 4.0 in spring-test makes it challenging to have Servlet 3.1 at runtime #26555

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

Closed
iay opened this issue Feb 16, 2021 · 4 comments
Assignees
Labels
in: test Issues in the test module in: web Issues in web modules (web, webmvc, webflux, websocket) type: regression A bug that is also a regression
Milestone

Comments

@iay
Copy link

iay commented Feb 16, 2021

Spring Framework 5.x is documented as requiring only Servlet 3.1 (EE7). However, a recent change (commit f22e2ac by @rstoyanchev, included in 5.3.4) introduces a reference to javax.servlet.http.HttpServletMapping into MockHttpServletRequest.

The referenced API is part of Servlet 4.0 (EE8) and is not present in Servlet 3.1.

It seems extremely unlikely that a dependency change to a new major version of the Servlet spec was intentionally introduced as part of a patch release of Spring Framework.

If I am not misunderstanding something here, it seems like this would need to be reverted.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 16, 2021
@sbrannen sbrannen self-assigned this Feb 16, 2021
@sbrannen
Copy link
Member

Spring Framework 5.3 supports Servlet 3.1 at runtime.

But... Spring's testing support for Servlet-based mocks requires Servlet 4.0. The Servlet API section of the Testing chapter states the following.

Since Spring Framework 5.0, the mock objects in org.springframework.mock.web are based on the Servlet 4.0 API.

Similar statements are present in the Javadoc for MockHttpServletRequest and related classes in that package.

Thus, you may need Servlet 4.0 on the classpath for your tests, but you are free to deploy your application on a server supporting Servlet 3.1.

In light of that, I am closing this issue.

@sbrannen sbrannen added status: invalid An issue that we don't feel is valid in: test Issues in the test module in: web Issues in web modules (web, webmvc, webflux, websocket) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 16, 2021
@gionn
Copy link

gionn commented Feb 17, 2021

Thus, you may need Servlet 4.0 on the classpath for your tests, but you are free to deploy your application on a server supporting Servlet 3.1.

Hi, we are using Spring with embedded Jetty on a maven project and I don't have any idea on how can I have a different version with different scopes of servlet-api (compile and test, in this case) without maven complaining about duplicated dependencies.

Any hints?

@rstoyanchev
Copy link
Contributor

We've decided to unroll the change in MockHttpServletRequest due to the practical challenges it causes in combination with Maven builds where the Servlet API is not provided.

@rstoyanchev rstoyanchev reopened this Feb 19, 2021
@rstoyanchev rstoyanchev assigned rstoyanchev and unassigned sbrannen Feb 19, 2021
@rstoyanchev rstoyanchev added type: regression A bug that is also a regression and removed status: invalid An issue that we don't feel is valid labels Feb 19, 2021
@rstoyanchev rstoyanchev changed the title spring-test 5.3.4 has bumped requirement to servlet 4.0 Dependency on Servlet 4.0 in spring-test make it challenging to have Servlet 3.1 at runtime Feb 19, 2021
@sbrannen sbrannen added this to the 5.3.5 milestone Feb 19, 2021
@sbrannen sbrannen changed the title Dependency on Servlet 4.0 in spring-test make it challenging to have Servlet 3.1 at runtime Dependency on Servlet 4.0 in spring-test makes it challenging to have Servlet 3.1 at runtime Feb 19, 2021
@iay
Copy link
Author

iay commented Feb 19, 2021

Thanks for the change in direction. We're also Maven-based and as far as I know there's no way to (a) code against Servlet 3.1 to make sure you're only using that API while also (b) having Servlet 4.0 available in your tests. Rolling back to Spring Framework 5.2.x was looking like our best option (and we may still need to do that, depending on our release timing).

This was referenced Mar 17, 2021
lxbzmy pushed a commit to lxbzmy/spring-framework that referenced this issue Mar 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module in: web Issues in web modules (web, webmvc, webflux, websocket) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

5 participants