-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Improve 404 error handling in Spring MVC #29491
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
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
type: enhancement
A general enhancement
Milestone
Comments
rstoyanchev
added a commit
that referenced
this issue
Jun 19, 2023
This was referenced Jul 13, 2023
snicoll
added a commit
that referenced
this issue
Apr 4, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
type: enhancement
A general enhancement
There are two places in Spring MVC that can call
sendError(SC_NOT_FOUND)
. One is theDispatcherServlet
and the otherResourceHttpRequestHandler
. This prevents applications from handling 404 errors, and also prevents the possibility for default error handling with an RFC 7807 problem details. By contrast, WebFlux raisesResponseStatusException(NOT_FOUND)
for both cases.The
DispatcherServlet
can be configured to raiseNoHandlerFoundException
through itsthrowExceptionIfNoHandlerFound
property, but by default it's false. ForResourceHttpRequestHandler
there is no way to customize the behavior.The goal for this issue is to phase out hard-coded use of
sendError
and allow consistent 404 handling:throwExceptionIfNoHandlerFound
property totrue
by default, and deprecate it for eventual removal. This will result in raisingNoHandlerFoundException
by default.ResourceHttpRequestHandler
to raise a similarNoResourceFoundException
, and provide default handling inResponseEntityExceptionHandler
as well as inDefaultHandlerExceptionResolver
.This should help to address spring-projects/spring-boot#7653. Boot will also need to update its own
throwExceptionIfNoHandlerFound
property that enforces afalse
value by default onDispatcherServlet
.The text was updated successfully, but these errors were encountered: