Skip to content

Commit 595ac43

Browse files
committed
Merge pull request #31660 from michaldo
* gh-31660: Polish "Document addition config for throw-exception-if-no-handler-found" Document addition config for throw-exception-if-no-handler-found Closes gh-31660
2 parents c11ff0d + fe944ca commit 595ac43

File tree

1 file changed

+5
-0
lines changed
  • spring-boot-project/spring-boot-docs/src/docs/asciidoc/web

1 file changed

+5
-0
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ and is incompatible with suffix pattern matching (configprop:spring.mvc.pathmatc
276276
configprop:spring.mvc.pathmatch.use-registered-suffix-pattern[deprecated]) or mapping the `DispatcherServlet`
277277
with a servlet prefix (configprop:spring.mvc.servlet.path[]).
278278

279+
By default, Spring MVC will send a 404 Not Found error response if a handler is not found for a request.
280+
To have a `NoHandlerFoundException` thrown instead, set configprop:spring.mvc.throw-exception-if-no-handler-found to `true`.
281+
Note that, by default, the <<web#web.servlet.spring-mvc.static-content, serving of static content>> is mapped to `+/**+` and will, therefore, provide a handler for all requests.
282+
For a `NoHandlerFoundException` to be thrown, you must also set configprop:spring.mvc.static-path-pattern[] to a more specific value such as `/resources/**` or set configprop:spring.web.resources.add-mappings[] to `false` to disable serving of static content entirely.
283+
279284

280285

281286
[[web.servlet.spring-mvc.binding-initializer]]

0 commit comments

Comments
 (0)