From c441bafe271ba46f54b5fc017fe3e4d8f25b31be Mon Sep 17 00:00:00 2001 From: Ionascu Stefan Ciprian Date: Mon, 8 Aug 2022 17:30:31 +0300 Subject: [PATCH 1/2] Document the DefaultServlet is no longer being enabled by default See gh-32004 --- .../src/docs/asciidoc/web/servlet.adoc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc index 1921c4c06d44..c4a177baea0d 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc @@ -127,7 +127,17 @@ If you set the configprop:spring.mvc.message-codes-resolver-format[] property `P By default, Spring Boot serves static content from a directory called `/static` (or `/public` or `/resources` or `/META-INF/resources`) in the classpath or from the root of the `ServletContext`. It uses the `ResourceHttpRequestHandler` from Spring MVC so that you can modify that behavior by adding your own `WebMvcConfigurer` and overriding the `addResourceHandlers` method. -In a stand-alone web application, the default servlet from the container is also enabled and acts as a fallback, serving content from the root of the `ServletContext` if Spring decides not to handle it. +In a stand-alone web application, default servlet is not enabled. It can be enabled as follows: + + +[source,yaml,indent=0,subs="verbatim",configprops,configblocks] +---- + server: + servlet: + register-default-servlet: true +---- + +If the default servlet is enablend it acts as a fallback, serving content from the root of the `ServletContext` if Spring decides not to handle it. Most of the time, this does not happen (unless you modify the default MVC configuration), because Spring can always handle requests through the `DispatcherServlet`. By default, resources are mapped on `+/**+`, but you can tune that with the configprop:spring.mvc.static-path-pattern[] property. From 12c1da275b630b301d620c919d889f4bf3d53c67 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 9 Aug 2022 09:47:36 +0200 Subject: [PATCH 2/2] Polish contribution See gh-32004 --- .../src/docs/asciidoc/web/servlet.adoc | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc index c4a177baea0d..d149e4742022 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc @@ -127,17 +127,10 @@ If you set the configprop:spring.mvc.message-codes-resolver-format[] property `P By default, Spring Boot serves static content from a directory called `/static` (or `/public` or `/resources` or `/META-INF/resources`) in the classpath or from the root of the `ServletContext`. It uses the `ResourceHttpRequestHandler` from Spring MVC so that you can modify that behavior by adding your own `WebMvcConfigurer` and overriding the `addResourceHandlers` method. -In a stand-alone web application, default servlet is not enabled. It can be enabled as follows: +In a stand-alone web application, the default servlet from the container is not enabled. +It can be enabled using the configprop:server.servlet.register-default-servlet[] property. - -[source,yaml,indent=0,subs="verbatim",configprops,configblocks] ----- - server: - servlet: - register-default-servlet: true ----- - -If the default servlet is enablend it acts as a fallback, serving content from the root of the `ServletContext` if Spring decides not to handle it. +The default servlet acts as a fallback, serving content from the root of the `ServletContext` if Spring decides not to handle it. Most of the time, this does not happen (unless you modify the default MVC configuration), because Spring can always handle requests through the `DispatcherServlet`. By default, resources are mapped on `+/**+`, but you can tune that with the configprop:spring.mvc.static-path-pattern[] property.