Browse Source

Move "Customize the whitelabel Error Page" into Spring MVC howto

Closes gh-41624
pull/42700/head
Moritz Halbritter 1 year ago
parent
commit
89bf2fc7e6
  1. 2
      spring-boot-project/spring-boot-docs/src/docs/antora/modules/ROOT/pages/redirect.adoc
  2. 20
      spring-boot-project/spring-boot-docs/src/docs/antora/modules/how-to/pages/actuator.adoc
  3. 20
      spring-boot-project/spring-boot-docs/src/docs/antora/modules/how-to/pages/spring-mvc.adoc

2
spring-boot-project/spring-boot-docs/src/docs/antora/modules/ROOT/pages/redirect.adoc

@ -329,7 +329,6 @@ @@ -329,7 +329,6 @@
* xref:gradle-plugin:running.adoc#running-your-application.using-a-test-main-class[gradle-plugin#running-your-application.using-a-test-main-class]
* xref:how-to:actuator.adoc#howto.actuator[#howto.actuator]
* xref:how-to:actuator.adoc#howto.actuator.change-http-port-or-address[#howto.actuator.change-http-port-or-address]
* xref:how-to:actuator.adoc#howto.actuator.customize-whitelabel-error-page[#howto.actuator.customize-whitelabel-error-page]
* xref:how-to:actuator.adoc#howto.actuator.customizing-sanitization[#howto.actuator.customizing-sanitization]
* xref:how-to:actuator.adoc#howto.actuator.map-health-indicators-to-metrics[#howto.actuator.map-health-indicators-to-metrics]
* xref:how-to:aot.adoc#howto.aot[#howto.aot]
@ -435,6 +434,7 @@ @@ -435,6 +434,7 @@
* xref:how-to:spring-mvc.adoc#howto.spring-mvc.customize-jackson-objectmapper[#howto.spring-mvc.customize-jackson-objectmapper]
* xref:how-to:spring-mvc.adoc#howto.spring-mvc.customize-responsebody-rendering[#howto.spring-mvc.customize-responsebody-rendering]
* xref:how-to:spring-mvc.adoc#howto.spring-mvc.customize-view-resolvers[#howto.spring-mvc.customize-view-resolvers]
* xref:how-to:spring-mvc.adoc#howto.spring-mvc.customize-whitelabel-error-page[#howto.actuator.customize-whitelabel-error-page]
* xref:how-to:spring-mvc.adoc#howto.spring-mvc.multipart-file-uploads[#howto.spring-mvc.multipart-file-uploads]
* xref:how-to:spring-mvc.adoc#howto.spring-mvc.switch-off-default-configuration[#howto.spring-mvc.switch-off-default-configuration]
* xref:how-to:spring-mvc.adoc#howto.spring-mvc.switch-off-dispatcherservlet[#howto.spring-mvc.switch-off-dispatcherservlet]

20
spring-boot-project/spring-boot-docs/src/docs/antora/modules/how-to/pages/actuator.adoc

@ -17,26 +17,6 @@ For more detail, see the javadoc:org.springframework.boot.actuate.autoconfigure. @@ -17,26 +17,6 @@ For more detail, see the javadoc:org.springframework.boot.actuate.autoconfigure.
[[howto.actuator.customize-whitelabel-error-page]]
== Customize the '`whitelabel`' Error Page
Spring Boot installs a '`whitelabel`' error page that you see in a browser client if you encounter a server error (machine clients consuming JSON and other media types should see a sensible response with the right error code).
NOTE: Set `server.error.whitelabel.enabled=false` to switch the default error page off.
Doing so restores the default of the servlet container that you are using.
Note that Spring Boot still tries to resolve the error view, so you should probably add your own error page rather than disabling it completely.
Overriding the error page with your own depends on the templating technology that you use.
For example, if you use Thymeleaf, you can add an `error.html` template.
If you use FreeMarker, you can add an `error.ftlh` template.
In general, you need a `View` that resolves with a name of `error` or a `@Controller` that handles the `/error` path.
Unless you replaced some of the default configuration, you should find a `BeanNameViewResolver` in your `ApplicationContext`, so a `@Bean` named `error` would be one way of doing that.
See {code-spring-boot-autoconfigure-src}/web/servlet/error/ErrorMvcAutoConfiguration.java[`ErrorMvcAutoConfiguration`] for more options.
See also the section on xref:reference:web/servlet.adoc#web.servlet.spring-mvc.error-handling[] for details of how to register handlers in the servlet container.
[[howto.actuator.customizing-sanitization]]
== Customizing Sanitization

20
spring-boot-project/spring-boot-docs/src/docs/antora/modules/how-to/pages/spring-mvc.adoc

@ -240,3 +240,23 @@ For more detail, see the following sections: @@ -240,3 +240,23 @@ For more detail, see the following sections:
* {code-spring-boot-autoconfigure-src}/thymeleaf/ThymeleafAutoConfiguration.java[`ThymeleafAutoConfiguration`]
* {code-spring-boot-autoconfigure-src}/freemarker/FreeMarkerAutoConfiguration.java[`FreeMarkerAutoConfiguration`]
* {code-spring-boot-autoconfigure-src}/groovy/template/GroovyTemplateAutoConfiguration.java[`GroovyTemplateAutoConfiguration`]
[[howto.spring-mvc.customize-whitelabel-error-page]]
== Customize the '`whitelabel`' Error Page
Spring Boot installs a '`whitelabel`' error page that you see in a browser client if you encounter a server error (machine clients consuming JSON and other media types should see a sensible response with the right error code).
NOTE: Set `server.error.whitelabel.enabled=false` to switch the default error page off.
Doing so restores the default of the servlet container that you are using.
Note that Spring Boot still tries to resolve the error view, so you should probably add your own error page rather than disabling it completely.
Overriding the error page with your own depends on the templating technology that you use.
For example, if you use Thymeleaf, you can add an `error.html` template.
If you use FreeMarker, you can add an `error.ftlh` template.
In general, you need a `View` that resolves with a name of `error` or a `@Controller` that handles the `/error` path.
Unless you replaced some of the default configuration, you should find a `BeanNameViewResolver` in your `ApplicationContext`, so a `@Bean` named `error` would be one way of doing that.
See {code-spring-boot-autoconfigure-src}/web/servlet/error/ErrorMvcAutoConfiguration.java[`ErrorMvcAutoConfiguration`] for more options.
See also the section on xref:reference:web/servlet.adoc#web.servlet.spring-mvc.error-handling[] for details of how to register handlers in the servlet container.

Loading…
Cancel
Save