diff --git a/framework-docs/framework-docs.gradle b/framework-docs/framework-docs.gradle
index 67f6d18dcf35..ce7e6c49c922 100644
--- a/framework-docs/framework-docs.gradle
+++ b/framework-docs/framework-docs.gradle
@@ -63,12 +63,16 @@ dependencies {
api(project(":spring-jdbc"))
api(project(":spring-jms"))
api(project(":spring-web"))
+ api(project(":spring-webmvc"))
+ api(project(":spring-context-support"))
api("org.jetbrains.kotlin:kotlin-stdlib")
api("jakarta.jms:jakarta.jms-api")
api("jakarta.servlet:jakarta.servlet-api")
api("org.apache.commons:commons-dbcp2:2.11.0")
api("com.mchange:c3p0:0.9.5.5")
+ api("com.fasterxml.jackson.core:jackson-databind")
+ api("com.fasterxml.jackson.module:jackson-module-parameter-names")
implementation(project(":spring-core-test"))
implementation("org.assertj:assertj-core")
diff --git a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/advanced-java.adoc b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/advanced-java.adoc
index dbcdcaccb015..b4f501e7331c 100644
--- a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/advanced-java.adoc
+++ b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/advanced-java.adoc
@@ -12,30 +12,7 @@ For advanced mode, you can remove `@EnableWebMvc` and extend directly from
`DelegatingWebMvcConfiguration` instead of implementing `WebMvcConfigurer`,
as the following example shows:
-[tabs]
-======
-Java::
-+
-[source,java,indent=0,subs="verbatim,quotes",role="primary"]
-----
- @Configuration
- public class WebConfig extends DelegatingWebMvcConfiguration {
-
- // ...
- }
-----
-
-Kotlin::
-+
-[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
-----
- @Configuration
- class WebConfig : DelegatingWebMvcConfiguration() {
-
- // ...
- }
-----
-======
+include-code::./WebConfiguration[tag=snippet,indent=0]
You can keep existing methods in `WebConfig`, but you can now also override bean declarations
from the base class, and you can still have any number of other `WebMvcConfigurer` implementations on
diff --git a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/advanced-xml.adoc b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/advanced-xml.adoc
index bb7203372647..cc5a1130bc9f 100644
--- a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/advanced-xml.adoc
+++ b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/advanced-xml.adoc
@@ -5,39 +5,7 @@ The MVC namespace does not have an advanced mode. If you need to customize a pro
a bean that you cannot change otherwise, you can use the `BeanPostProcessor` lifecycle
hook of the Spring `ApplicationContext`, as the following example shows:
-[tabs]
-======
-Java::
-+
-[source,java,indent=0,subs="verbatim,quotes",role="primary"]
-----
- @Component
- public class MyPostProcessor implements BeanPostProcessor {
-
- public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
- // ...
- }
- }
-----
-
-Kotlin::
-+
-[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
-----
- @Component
- class MyPostProcessor : BeanPostProcessor {
-
- override fun postProcessBeforeInitialization(bean: Any, name: String): Any {
- // ...
- }
- }
-----
-======
-
+include-code::./MyPostProcessor[tag=snippet,indent=0]
Note that you need to declare `MyPostProcessor` as a bean, either explicitly in XML or
by letting it be detected through a `` declaration.
-
-
-
-
diff --git a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/content-negotiation.adoc b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/content-negotiation.adoc
index c209826dcbf8..3850a9931ba1 100644
--- a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/content-negotiation.adoc
+++ b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/content-negotiation.adoc
@@ -13,59 +13,9 @@ strategy over path extensions. See
xref:web/webmvc/mvc-controller/ann-requestmapping.adoc#mvc-ann-requestmapping-suffix-pattern-match[Suffix Match] and xref:web/webmvc/mvc-controller/ann-requestmapping.adoc#mvc-ann-requestmapping-rfd[Suffix Match and RFD] for
more details.
-In Java configuration, you can customize requested content type resolution, as the
-following example shows:
+You can customize requested content type resolution, as the following example shows:
-[tabs]
-======
-Java::
-+
-[source,java,indent=0,subs="verbatim,quotes",role="primary"]
-----
- @Configuration
- @EnableWebMvc
- public class WebConfig implements WebMvcConfigurer {
-
- @Override
- public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
- configurer.mediaType("json", MediaType.APPLICATION_JSON);
- configurer.mediaType("xml", MediaType.APPLICATION_XML);
- }
- }
-----
-
-Kotlin::
-+
-[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
-----
- @Configuration
- @EnableWebMvc
- class WebConfig : WebMvcConfigurer {
-
- override fun configureContentNegotiation(configurer: ContentNegotiationConfigurer) {
- configurer.mediaType("json", MediaType.APPLICATION_JSON)
- configurer.mediaType("xml", MediaType.APPLICATION_XML)
- }
- }
-----
-======
-
-
-The following example shows how to achieve the same configuration in XML:
-
-[source,xml,indent=0,subs="verbatim,quotes"]
-----
-
-
-
-
-
- json=application/json
- xml=application/xml
-
-
-
-----
+include-code::./WebConfiguration[tag=snippet,indent=0]
diff --git a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/conversion.adoc b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/conversion.adoc
index 35d0998934de..2e8286fa8974 100644
--- a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/conversion.adoc
+++ b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/conversion.adoc
@@ -6,119 +6,16 @@
By default, formatters for various number and date types are installed, along with support
for customization via `@NumberFormat` and `@DateTimeFormat` on fields.
-To register custom formatters and converters in Java config, use the following:
+To register custom formatters and converters, use the following:
-[tabs]
-======
-Java::
-+
-[source,java,indent=0,subs="verbatim,quotes",role="primary"]
-----
- @Configuration
- @EnableWebMvc
- public class WebConfig implements WebMvcConfigurer {
-
- @Override
- public void addFormatters(FormatterRegistry registry) {
- // ...
- }
- }
-----
-
-Kotlin::
-+
-[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
-----
- @Configuration
- @EnableWebMvc
- class WebConfig : WebMvcConfigurer {
-
- override fun addFormatters(registry: FormatterRegistry) {
- // ...
- }
- }
-----
-======
-
-To do the same in XML config, use the following:
-
-[source,xml,indent=0,subs="verbatim,quotes"]
-----
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-----
+include-code::./WebConfiguration[tag=snippet,indent=0]
By default Spring MVC considers the request Locale when parsing and formatting date
values. This works for forms where dates are represented as Strings with "input" form
fields. For "date" and "time" form fields, however, browsers use a fixed format defined
in the HTML spec. For such cases date and time formatting can be customized as follows:
-[tabs]
-======
-Java::
-+
-[source,java,indent=0,subs="verbatim,quotes",role="primary"]
-----
- @Configuration
- @EnableWebMvc
- public class WebConfig implements WebMvcConfigurer {
-
- @Override
- public void addFormatters(FormatterRegistry registry) {
- DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
- registrar.setUseIsoFormat(true);
- registrar.registerFormatters(registry);
- }
- }
-----
-
-Kotlin::
-+
-[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
-----
- @Configuration
- @EnableWebMvc
- class WebConfig : WebMvcConfigurer {
-
- override fun addFormatters(registry: FormatterRegistry) {
- val registrar = DateTimeFormatterRegistrar()
- registrar.setUseIsoFormat(true)
- registrar.registerFormatters(registry)
- }
- }
-----
-======
+include-code::./DateTimeWebConfiguration[tag=snippet,indent=0]
NOTE: See xref:core/validation/format.adoc#format-FormatterRegistrar-SPI[the `FormatterRegistrar` SPI]
and the `FormattingConversionServiceFactoryBean` for more information on when to use
diff --git a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/customize.adoc b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/customize.adoc
index dd7cf7e635e1..a42ea1388a44 100644
--- a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/customize.adoc
+++ b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/customize.adoc
@@ -6,33 +6,7 @@
In Java configuration, you can implement the `WebMvcConfigurer` interface, as the
following example shows:
-[tabs]
-======
-Java::
-+
-[source,java,indent=0,subs="verbatim,quotes",role="primary"]
-----
- @Configuration
- @EnableWebMvc
- public class WebConfig implements WebMvcConfigurer {
-
- // Implement configuration methods...
- }
-----
-
-Kotlin::
-+
-[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
-----
- @Configuration
- @EnableWebMvc
- class WebConfig : WebMvcConfigurer {
-
- // Implement configuration methods...
- }
-----
-======
-
+include-code::./WebConfiguration[tag=snippet,indent=0]
In XML, you can check attributes and sub-elements of ``. You can
view the https://schema.spring.io/mvc/spring-mvc.xsd[Spring MVC XML schema] or use
diff --git a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/default-servlet-handler.adoc b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/default-servlet-handler.adoc
index 8251cd53528b..2ad51145d66b 100644
--- a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/default-servlet-handler.adoc
+++ b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/default-servlet-handler.adoc
@@ -15,44 +15,7 @@ lower than that of the `DefaultServletHttpRequestHandler`, which is `Integer.MAX
The following example shows how to enable the feature by using the default setup:
-[tabs]
-======
-Java::
-+
-[source,java,indent=0,subs="verbatim,quotes",role="primary"]
-----
- @Configuration
- @EnableWebMvc
- public class WebConfig implements WebMvcConfigurer {
-
- @Override
- public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
- configurer.enable();
- }
- }
-----
-
-Kotlin::
-+
-[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
-----
- @Configuration
- @EnableWebMvc
- class WebConfig : WebMvcConfigurer {
-
- override fun configureDefaultServletHandling(configurer: DefaultServletHandlerConfigurer) {
- configurer.enable()
- }
- }
-----
-======
-
-The following example shows how to achieve the same configuration in XML:
-
-[source,xml,indent=0,subs="verbatim,quotes"]
-----
-
-----
+include-code::./WebConfiguration[tag=snippet,indent=0]
The caveat to overriding the `/` Servlet mapping is that the `RequestDispatcher` for the
default Servlet must be retrieved by name rather than by path. The
@@ -63,45 +26,4 @@ If the default Servlet has been custom-configured with a different name, or if a
different Servlet container is being used where the default Servlet name is unknown,
then you must explicitly provide the default Servlet's name, as the following example shows:
-[tabs]
-======
-Java::
-+
-[source,java,indent=0,subs="verbatim,quotes",role="primary"]
-----
- @Configuration
- @EnableWebMvc
- public class WebConfig implements WebMvcConfigurer {
-
- @Override
- public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
- configurer.enable("myCustomDefaultServlet");
- }
- }
-----
-
-Kotlin::
-+
-[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
-----
- @Configuration
- @EnableWebMvc
- class WebConfig : WebMvcConfigurer {
-
- override fun configureDefaultServletHandling(configurer: DefaultServletHandlerConfigurer) {
- configurer.enable("myCustomDefaultServlet")
- }
- }
-----
-======
-
-
-The following example shows how to achieve the same configuration in XML:
-
-[source,xml,indent=0,subs="verbatim,quotes"]
-----
-
-----
-
-
-
+include-code::./CustomDefaultServletConfiguration[tag=snippet,indent=0]
diff --git a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/enable.adoc b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/enable.adoc
index bec619f91f3d..e48c97cd6273 100644
--- a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/enable.adoc
+++ b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/enable.adoc
@@ -3,50 +3,11 @@
[.small]#xref:web/webflux/config.adoc#webflux-config-enable[See equivalent in the Reactive stack]#
-In Java configuration, you can use the `@EnableWebMvc` annotation to enable MVC
-configuration, as the following example shows:
-
-[tabs]
-======
-Java::
-+
-[source,java,indent=0,subs="verbatim,quotes",role="primary"]
-----
- @Configuration
- @EnableWebMvc
- public class WebConfig {
- }
-----
-
-Kotlin::
-+
-[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
-----
- @Configuration
- @EnableWebMvc
- class WebConfig
-----
-======
-
-In XML configuration, you can use the `` element to enable MVC
-configuration, as the following example shows:
-
-[source,xml,indent=0,subs="verbatim,quotes"]
-----
-
-
-
-
-
-
-----
+You can use the `@EnableWebMvc` annotation to enable MVC configuration with programmatic configuration, or `` with XML configuration, as the following example shows:
+
+include-code::./WebConfiguration[tag=snippet,indent=0]
+
+NOTE: When using Spring Boot, you may want to use `@Configuration` class of type `WebMvcConfigurer` but without `@EnableWebMvc` to keep Spring Boot MVC customizations. See more details in the xref:web/webmvc/mvc-config/customize.adoc[the MVC Config API section] and in {spring-boot-docs}/web.html#web.servlet.spring-mvc.auto-configuration[the dedicated Spring Boot documentation].
The preceding example registers a number of Spring MVC
xref:web/webmvc/mvc-servlet/special-bean-types.adoc[infrastructure beans] and adapts to dependencies
diff --git a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/interceptors.adoc b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/interceptors.adoc
index 36c7d32956e5..165673bec8ac 100644
--- a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/interceptors.adoc
+++ b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/interceptors.adoc
@@ -1,56 +1,9 @@
[[mvc-config-interceptors]]
= Interceptors
-In Java configuration, you can register interceptors to apply to incoming requests, as
-the following example shows:
+You can register interceptors to apply to incoming requests, as the following example shows:
-[tabs]
-======
-Java::
-+
-[source,java,indent=0,subs="verbatim",role="primary"]
-----
- @Configuration
- @EnableWebMvc
- public class WebConfig implements WebMvcConfigurer {
-
- @Override
- public void addInterceptors(InterceptorRegistry registry) {
- registry.addInterceptor(new LocaleChangeInterceptor());
- registry.addInterceptor(new ThemeChangeInterceptor()).addPathPatterns("/**").excludePathPatterns("/admin/**");
- }
- }
-----
-
-Kotlin::
-+
-[source,kotlin,indent=0,subs="verbatim",role="secondary"]
-----
- @Configuration
- @EnableWebMvc
- class WebConfig : WebMvcConfigurer {
-
- override fun addInterceptors(registry: InterceptorRegistry) {
- registry.addInterceptor(LocaleChangeInterceptor())
- registry.addInterceptor(ThemeChangeInterceptor()).addPathPatterns("/**").excludePathPatterns("/admin/**")
- }
- }
-----
-======
-
-The following example shows how to achieve the same configuration in XML:
-
-[source,xml,indent=0,subs="verbatim"]
-----
-
-
-
-
-
-
-
-
-----
+include-code::./WebConfiguration[tag=snippet,indent=0]
NOTE: Interceptors are not ideally suited as a security layer due to the potential
for a mismatch with annotated controller path matching, which can also match trailing
diff --git a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/message-converters.adoc b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/message-converters.adoc
index fb1abadc4aca..ad09392ec7a5 100644
--- a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/message-converters.adoc
+++ b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/message-converters.adoc
@@ -15,48 +15,10 @@ Boot application, prefer to use the {spring-boot-docs}/web.html#web.servlet.spri
mechanism. Or alternatively, use `extendMessageConverters` to modify message converters
at the end.
-The following example adds XML and Jackson JSON converters with a customized
-`ObjectMapper` instead of the default ones:
+The following example adds XML and Jackson JSON converters with a customized `ObjectMapper`
+instead of the default ones:
-[tabs]
-======
-Java::
-+
-[source,java,indent=0,subs="verbatim,quotes",role="primary"]
-----
- @Configuration
- @EnableWebMvc
- public class WebConfiguration implements WebMvcConfigurer {
-
- @Override
- public void configureMessageConverters(List> converters) {
- Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
- .indentOutput(true)
- .dateFormat(new SimpleDateFormat("yyyy-MM-dd"))
- .modulesToInstall(new ParameterNamesModule());
- converters.add(new MappingJackson2HttpMessageConverter(builder.build()));
- converters.add(new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build()));
- }
- }
-----
-
-Kotlin::
-+
-[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
-----
- @Configuration
- @EnableWebMvc
- class WebConfiguration : WebMvcConfigurer {
-
- override fun configureMessageConverters(converters: MutableList>) {
- val builder = Jackson2ObjectMapperBuilder()
- .indentOutput(true)
- .dateFormat(SimpleDateFormat("yyyy-MM-dd"))
- .modulesToInstall(ParameterNamesModule())
- converters.add(MappingJackson2HttpMessageConverter(builder.build()))
- converters.add(MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build()))
-----
-======
+include-code::./WebConfiguration[tag=snippet,indent=0]
In the preceding example,
{spring-framework-api}/http/converter/json/Jackson2ObjectMapperBuilder.html[`Jackson2ObjectMapperBuilder`]
@@ -76,7 +38,7 @@ It also automatically registers the following well-known modules if they are det
* {jackson-github-org}/jackson-datatype-joda[jackson-datatype-joda]: Support for Joda-Time types.
* {jackson-github-org}/jackson-datatype-jsr310[jackson-datatype-jsr310]: Support for Java 8 Date and Time API types.
* {jackson-github-org}/jackson-datatype-jdk8[jackson-datatype-jdk8]: Support for other Java 8 types, such as `Optional`.
-* {jackson-github-org}/jackson-module-kotlin[`jackson-module-kotlin`]: Support for Kotlin classes and data classes.
+* {jackson-github-org}/jackson-module-kotlin[jackson-module-kotlin]: Support for Kotlin classes and data classes.
NOTE: Enabling indentation with Jackson XML support requires
https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.codehaus.woodstox%22%20AND%20a%3A%22woodstox-core-asl%22[`woodstox-core-asl`]
@@ -86,29 +48,3 @@ Other interesting Jackson modules are available:
* https://github.com/zalando/jackson-datatype-money[jackson-datatype-money]: Support for `javax.money` types (unofficial module).
* {jackson-github-org}/jackson-datatype-hibernate[jackson-datatype-hibernate]: Support for Hibernate-specific types and properties (including lazy-loading aspects).
-
-The following example shows how to achieve the same configuration in XML:
-
-[source,xml,indent=0,subs="verbatim,quotes"]
-----
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-----
-
-
-
diff --git a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/path-matching.adoc b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/path-matching.adoc
index 989ad29c0c5a..a0f33fee3ec1 100644
--- a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/path-matching.adoc
+++ b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/path-matching.adoc
@@ -7,61 +7,6 @@ You can customize options related to path matching and treatment of the URL.
For details on the individual options, see the
{spring-framework-api}/web/servlet/config/annotation/PathMatchConfigurer.html[`PathMatchConfigurer`] javadoc.
-The following example shows how to customize path matching in Java configuration:
-
-[tabs]
-======
-Java::
-+
-[source,java,indent=0,subs="verbatim,quotes",role="primary"]
-----
- @Configuration
- @EnableWebMvc
- public class WebConfig implements WebMvcConfigurer {
-
- @Override
- public void configurePathMatch(PathMatchConfigurer configurer) {
- configurer.addPathPrefix("/api", HandlerTypePredicate.forAnnotation(RestController.class));
- }
-
- private PathPatternParser patternParser() {
- // ...
- }
- }
-----
-
-Kotlin::
-+
-[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
-----
- @Configuration
- @EnableWebMvc
- class WebConfig : WebMvcConfigurer {
-
- override fun configurePathMatch(configurer: PathMatchConfigurer) {
- configurer.addPathPrefix("/api", HandlerTypePredicate.forAnnotation(RestController::class.java))
- }
-
- fun patternParser(): PathPatternParser {
- //...
- }
- }
-----
-======
-
-The following example shows how to customize path matching in XML configuration:
-
-[source,xml,indent=0,subs="verbatim,quotes"]
-----
-
-
-
-
-
-
-----
-
-
+The following example shows how to customize path matching:
+include-code::./WebConfiguration[tag=snippet,indent=0]
diff --git a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/static-resources.adoc b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/static-resources.adoc
index e56686152863..008832cfd954 100644
--- a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/static-resources.adoc
+++ b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/static-resources.adoc
@@ -13,52 +13,9 @@ expiration to ensure maximum use of the browser cache and a reduction in HTTP re
made by the browser. The `Last-Modified` information is deduced from `Resource#lastModified`
so that HTTP conditional requests are supported with `"Last-Modified"` headers.
-The following listing shows how to do so with Java configuration:
-
-[tabs]
-======
-Java::
-+
-[source,java,indent=0,subs="verbatim",role="primary"]
-----
- @Configuration
- @EnableWebMvc
- public class WebConfig implements WebMvcConfigurer {
-
- @Override
- public void addResourceHandlers(ResourceHandlerRegistry registry) {
- registry.addResourceHandler("/resources/**")
- .addResourceLocations("/public", "classpath:/static/")
- .setCacheControl(CacheControl.maxAge(Duration.ofDays(365)));
- }
- }
-----
-
-Kotlin::
-+
-[source,kotlin,indent=0,subs="verbatim",role="secondary"]
-----
- @Configuration
- @EnableWebMvc
- class WebConfig : WebMvcConfigurer {
-
- override fun addResourceHandlers(registry: ResourceHandlerRegistry) {
- registry.addResourceHandler("/resources/**")
- .addResourceLocations("/public", "classpath:/static/")
- .setCacheControl(CacheControl.maxAge(Duration.ofDays(365)))
- }
- }
-----
-======
-
-The following example shows how to achieve the same configuration in XML:
-
-[source,xml,indent=0,subs="verbatim,quotes"]
-----
-
-----
+The following listing shows how to do so:
+
+include-code::./WebConfiguration[tag=snippet,indent=0]
See also
xref:web/webmvc/mvc-caching.adoc#mvc-caching-static-resources[HTTP caching support for static resources].
@@ -73,60 +30,9 @@ computed from the content, a fixed application version, or other. A
`ContentVersionStrategy` (MD5 hash) is a good choice -- with some notable exceptions, such as
JavaScript resources used with a module loader.
-The following example shows how to use `VersionResourceResolver` in Java configuration:
-
-[tabs]
-======
-Java::
-+
-[source,java,indent=0,subs="verbatim",role="primary"]
-----
- @Configuration
- @EnableWebMvc
- public class WebConfig implements WebMvcConfigurer {
-
- @Override
- public void addResourceHandlers(ResourceHandlerRegistry registry) {
- registry.addResourceHandler("/resources/**")
- .addResourceLocations("/public/")
- .resourceChain(true)
- .addResolver(new VersionResourceResolver().addContentVersionStrategy("/**"));
- }
- }
-----
-
-Kotlin::
-+
-[source,kotlin,indent=0,subs="verbatim",role="secondary"]
-----
- @Configuration
- @EnableWebMvc
- class WebConfig : WebMvcConfigurer {
-
- override fun addResourceHandlers(registry: ResourceHandlerRegistry) {
- registry.addResourceHandler("/resources/**")
- .addResourceLocations("/public/")
- .resourceChain(true)
- .addResolver(VersionResourceResolver().addContentVersionStrategy("/**"))
- }
- }
-----
-======
-
-The following example shows how to achieve the same configuration in XML:
-
-[source,xml,indent=0,subs="verbatim"]
-----
-
-
-
-
-
-
-
-
-
-----
+The following example shows how to use `VersionResourceResolver`:
+
+include-code::./VersionedConfiguration[tag=snippet,indent=0]
You can then use `ResourceUrlProvider` to rewrite URLs and apply the full chain of resolvers and
transformers -- for example, to insert versions. The MVC configuration provides a `ResourceUrlProvider`
diff --git a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/validation.adoc b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/validation.adoc
index b307b8fc8c8c..b867977160fd 100644
--- a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/validation.adoc
+++ b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/validation.adoc
@@ -8,93 +8,15 @@ on the classpath (for example, Hibernate Validator), the `LocalValidatorFactoryB
registered as a global xref:core/validation/validator.adoc[Validator] for use with `@Valid` and
`@Validated` on controller method arguments.
-In Java configuration, you can customize the global `Validator` instance, as the
+You can customize the global `Validator` instance, as the
following example shows:
-[tabs]
-======
-Java::
-+
-[source,java,indent=0,subs="verbatim,quotes",role="primary"]
-----
- @Configuration
- @EnableWebMvc
- public class WebConfig implements WebMvcConfigurer {
-
- @Override
- public Validator getValidator() {
- // ...
- }
- }
-----
-
-Kotlin::
-+
-[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
-----
- @Configuration
- @EnableWebMvc
- class WebConfig : WebMvcConfigurer {
-
- override fun getValidator(): Validator {
- // ...
- }
- }
-----
-======
-
-The following example shows how to achieve the same configuration in XML:
-
-[source,xml,indent=0,subs="verbatim,quotes"]
-----
-
-
-
-
-
-
-----
+include-code::./WebConfiguration[tag=snippet,indent=0]
Note that you can also register `Validator` implementations locally, as the following
example shows:
-[tabs]
-======
-Java::
-+
-[source,java,indent=0,subs="verbatim,quotes",role="primary"]
-----
- @Controller
- public class MyController {
-
- @InitBinder
- protected void initBinder(WebDataBinder binder) {
- binder.addValidators(new FooValidator());
- }
- }
-----
-
-Kotlin::
-+
-[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
-----
- @Controller
- class MyController {
-
- @InitBinder
- protected fun initBinder(binder: WebDataBinder) {
- binder.addValidators(FooValidator())
- }
- }
-----
-======
+include-code::./MyController[tag=snippet,indent=0]
TIP: If you need to have a `LocalValidatorFactoryBean` injected somewhere, create a bean and
mark it with `@Primary` in order to avoid conflict with the one declared in the MVC configuration.
diff --git a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/view-controller.adoc b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/view-controller.adoc
index 91811b7f415c..47d803b10c80 100644
--- a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/view-controller.adoc
+++ b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/view-controller.adoc
@@ -5,47 +5,9 @@ This is a shortcut for defining a `ParameterizableViewController` that immediate
forwards to a view when invoked. You can use it in static cases when there is no Java controller
logic to run before the view generates the response.
-The following example of Java configuration forwards a request for `/` to a view called `home`:
+The following example forwards a request for `/` to a view called `home`:
-[tabs]
-======
-Java::
-+
-[source,java,indent=0,subs="verbatim,quotes",role="primary"]
-----
- @Configuration
- @EnableWebMvc
- public class WebConfig implements WebMvcConfigurer {
-
- @Override
- public void addViewControllers(ViewControllerRegistry registry) {
- registry.addViewController("/").setViewName("home");
- }
- }
-----
-
-Kotlin::
-+
-[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
-----
- @Configuration
- @EnableWebMvc
- class WebConfig : WebMvcConfigurer {
-
- override fun addViewControllers(registry: ViewControllerRegistry) {
- registry.addViewController("/").setViewName("home")
- }
- }
-----
-======
-
-The following example achieves the same thing as the preceding example, but with XML, by
-using the `` element:
-
-[source,xml,indent=0,subs="verbatim,quotes"]
-----
-
-----
+include-code::./WebConfiguration[tag=snippet,indent=0]
If an `@RequestMapping` method is mapped to a URL for any HTTP method then a view
controller cannot be used to handle the same URL. This is because a match by URL to an
diff --git a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/view-resolvers.adoc b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/view-resolvers.adoc
index cea23436efd8..5a0de6171d3f 100644
--- a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/view-resolvers.adoc
+++ b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/view-resolvers.adoc
@@ -5,127 +5,12 @@
The MVC configuration simplifies the registration of view resolvers.
-The following Java configuration example configures content negotiation view
-resolution by using JSP and Jackson as a default `View` for JSON rendering:
+The following example configures content negotiation view resolution by using JSP and Jackson as a
+default `View` for JSON rendering:
-[tabs]
-======
-Java::
-+
-[source,java,indent=0,subs="verbatim,quotes",role="primary"]
-----
- @Configuration
- @EnableWebMvc
- public class WebConfig implements WebMvcConfigurer {
-
- @Override
- public void configureViewResolvers(ViewResolverRegistry registry) {
- registry.enableContentNegotiation(new MappingJackson2JsonView());
- registry.jsp();
- }
- }
-----
-
-Kotlin::
-+
-[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
-----
- @Configuration
- @EnableWebMvc
- class WebConfig : WebMvcConfigurer {
-
- override fun configureViewResolvers(registry: ViewResolverRegistry) {
- registry.enableContentNegotiation(MappingJackson2JsonView())
- registry.jsp()
- }
- }
-----
-======
-
-
-The following example shows how to achieve the same configuration in XML:
-
-[source,xml,indent=0,subs="verbatim,quotes"]
-----
-
-
-
-
-
-
-
-
-----
+include-code::./WebConfiguration[tag=snippet,indent=0]
Note, however, that FreeMarker, Groovy Markup, and script templates also require
-configuration of the underlying view technology.
-
-The MVC namespace provides dedicated elements. The following example works with FreeMarker:
-
-[source,xml,indent=0,subs="verbatim,quotes"]
-----
-
-
-
-
-
-
-
-
-
-
-
-
-----
-
-In Java configuration, you can add the respective `Configurer` bean,
-as the following example shows:
-
-[tabs]
-======
-Java::
-+
-[source,java,indent=0,subs="verbatim,quotes",role="primary"]
-----
- @Configuration
- @EnableWebMvc
- public class WebConfig implements WebMvcConfigurer {
-
- @Override
- public void configureViewResolvers(ViewResolverRegistry registry) {
- registry.enableContentNegotiation(new MappingJackson2JsonView());
- registry.freeMarker().cache(false);
- }
-
- @Bean
- public FreeMarkerConfigurer freeMarkerConfigurer() {
- FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
- configurer.setTemplateLoaderPath("/freemarker");
- return configurer;
- }
- }
-----
-
-Kotlin::
-+
-[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
-----
- @Configuration
- @EnableWebMvc
- class WebConfig : WebMvcConfigurer {
-
- override fun configureViewResolvers(registry: ViewResolverRegistry) {
- registry.enableContentNegotiation(MappingJackson2JsonView())
- registry.freeMarker().cache(false)
- }
-
- @Bean
- fun freeMarkerConfigurer() = FreeMarkerConfigurer().apply {
- setTemplateLoaderPath("/freemarker")
- }
- }
-----
-======
-
-
+configuration of the underlying view technology. The following example works with FreeMarker:
+include-code::./FreeMarkerConfiguration[tag=snippet,indent=0]
diff --git a/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigadvancedjava/WebConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigadvancedjava/WebConfiguration.java
new file mode 100644
index 000000000000..f6f386efc17b
--- /dev/null
+++ b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigadvancedjava/WebConfiguration.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigadvancedjava;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration;
+
+// tag::snippet[]
+@Configuration
+public class WebConfiguration extends DelegatingWebMvcConfiguration {
+
+ // ...
+}
+// end::snippet[]
\ No newline at end of file
diff --git a/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigadvancedxml/MyPostProcessor.java b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigadvancedxml/MyPostProcessor.java
new file mode 100644
index 000000000000..1c3886417436
--- /dev/null
+++ b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigadvancedxml/MyPostProcessor.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigadvancedxml;
+
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.config.BeanPostProcessor;
+import org.springframework.stereotype.Component;
+
+// tag::snippet[]
+@Component
+public class MyPostProcessor implements BeanPostProcessor {
+
+ public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
+ // ...
+ }
+}
+// end::snippet[]
diff --git a/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigcontentnegotiation/WebConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigcontentnegotiation/WebConfiguration.java
new file mode 100644
index 000000000000..9697847decbc
--- /dev/null
+++ b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigcontentnegotiation/WebConfiguration.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigcontentnegotiation;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.MediaType;
+import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+// tag::snippet[]
+@Configuration
+public class WebConfiguration implements WebMvcConfigurer {
+
+ @Override
+ public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
+ configurer.mediaType("json", MediaType.APPLICATION_JSON);
+ configurer.mediaType("xml", MediaType.APPLICATION_XML);
+ }
+}
+// end::snippet[]
\ No newline at end of file
diff --git a/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigconversion/DateTimeWebConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigconversion/DateTimeWebConfiguration.java
new file mode 100644
index 000000000000..efa8b5090ad9
--- /dev/null
+++ b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigconversion/DateTimeWebConfiguration.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigconversion;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.format.FormatterRegistry;
+import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+// tag::snippet[]
+@Configuration
+public class DateTimeWebConfiguration implements WebMvcConfigurer {
+
+ @Override
+ public void addFormatters(FormatterRegistry registry) {
+ DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
+ registrar.setUseIsoFormat(true);
+ registrar.registerFormatters(registry);
+ }
+}
+// end::snippet[]
\ No newline at end of file
diff --git a/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigconversion/WebConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigconversion/WebConfiguration.java
new file mode 100644
index 000000000000..ec7166f54f60
--- /dev/null
+++ b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigconversion/WebConfiguration.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigconversion;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.format.FormatterRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+// tag::snippet[]
+@Configuration
+public class WebConfiguration implements WebMvcConfigurer {
+
+ @Override
+ public void addFormatters(FormatterRegistry registry) {
+ // ...
+ }
+}
+// end::snippet[]
\ No newline at end of file
diff --git a/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigcustomize/WebConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigcustomize/WebConfiguration.java
new file mode 100644
index 000000000000..f6aee7304608
--- /dev/null
+++ b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigcustomize/WebConfiguration.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigcustomize;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+// tag::snippet[]
+@Configuration
+public class WebConfiguration implements WebMvcConfigurer {
+
+ // Implement configuration methods...
+}
+// end::snippet[]
\ No newline at end of file
diff --git a/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigenable/WebConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigenable/WebConfiguration.java
new file mode 100644
index 000000000000..8616dd994fbb
--- /dev/null
+++ b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigenable/WebConfiguration.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigenable;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+
+// tag::snippet[]
+@Configuration
+@EnableWebMvc
+public class WebConfiguration {
+}
+// end::snippet[]
\ No newline at end of file
diff --git a/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfiginterceptors/WebConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfiginterceptors/WebConfiguration.java
new file mode 100644
index 000000000000..a087cca04faf
--- /dev/null
+++ b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfiginterceptors/WebConfiguration.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfiginterceptors;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
+import org.springframework.web.servlet.theme.ThemeChangeInterceptor;
+
+// tag::snippet[]
+@Configuration
+public class WebConfiguration implements WebMvcConfigurer {
+
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+ registry.addInterceptor(new LocaleChangeInterceptor());
+ registry.addInterceptor(new ThemeChangeInterceptor()).addPathPatterns("/**").excludePathPatterns("/admin/**");
+ }
+}
+// end::snippet[]
diff --git a/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigmessageconverters/WebConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigmessageconverters/WebConfiguration.java
new file mode 100644
index 000000000000..019a99a270cb
--- /dev/null
+++ b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigmessageconverters/WebConfiguration.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigmessageconverters;
+
+import java.text.SimpleDateFormat;
+import java.util.List;
+
+import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
+import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+// tag::snippet[]
+@Configuration
+public class WebConfiguration implements WebMvcConfigurer {
+
+ @Override
+ public void configureMessageConverters(List> converters) {
+ Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
+ .indentOutput(true)
+ .dateFormat(new SimpleDateFormat("yyyy-MM-dd"))
+ .modulesToInstall(new ParameterNamesModule());
+ converters.add(new MappingJackson2HttpMessageConverter(builder.build()));
+ converters.add(new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build()));
+ }
+}
+// end::snippet[]
diff --git a/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigpathmatching/WebConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigpathmatching/WebConfiguration.java
new file mode 100644
index 000000000000..be93fe127b6a
--- /dev/null
+++ b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigpathmatching/WebConfiguration.java
@@ -0,0 +1,23 @@
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigpathmatching;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.method.HandlerTypePredicate;
+import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+import org.springframework.web.util.pattern.PathPatternParser;
+
+// tag::snippet[]
+@Configuration
+public class WebConfiguration implements WebMvcConfigurer {
+
+ @Override
+ public void configurePathMatch(PathMatchConfigurer configurer) {
+ configurer.addPathPrefix("/api", HandlerTypePredicate.forAnnotation(RestController.class));
+ }
+
+ private PathPatternParser patternParser() {
+ // ...
+ }
+}
+// end::snippet[]
diff --git a/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigstaticresources/VersionedConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigstaticresources/VersionedConfiguration.java
new file mode 100644
index 000000000000..10c07a4eab7c
--- /dev/null
+++ b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigstaticresources/VersionedConfiguration.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigstaticresources;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+import org.springframework.web.servlet.resource.VersionResourceResolver;
+
+// tag::snippet[]
+@Configuration
+public class VersionedConfiguration implements WebMvcConfigurer {
+
+ @Override
+ public void addResourceHandlers(ResourceHandlerRegistry registry) {
+ registry.addResourceHandler("/resources/**")
+ .addResourceLocations("/public/")
+ .resourceChain(true)
+ .addResolver(new VersionResourceResolver().addContentVersionStrategy("/**"));
+ }
+}
+// end::snippet[]
diff --git a/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigstaticresources/WebConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigstaticresources/WebConfiguration.java
new file mode 100644
index 000000000000..46df090b4d13
--- /dev/null
+++ b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigstaticresources/WebConfiguration.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigstaticresources;
+
+import java.time.Duration;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.CacheControl;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+// tag::snippet[]
+@Configuration
+public class WebConfiguration implements WebMvcConfigurer {
+
+ @Override
+ public void addResourceHandlers(ResourceHandlerRegistry registry) {
+ registry.addResourceHandler("/resources/**")
+ .addResourceLocations("/public", "classpath:/static/")
+ .setCacheControl(CacheControl.maxAge(Duration.ofDays(365)));
+ }
+}
+// end::snippet[]
diff --git a/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigvalidation/FooValidator.java b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigvalidation/FooValidator.java
new file mode 100644
index 000000000000..5fc1c723632f
--- /dev/null
+++ b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigvalidation/FooValidator.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigvalidation;
+
+import org.springframework.validation.Errors;
+import org.springframework.validation.Validator;
+
+public class FooValidator implements Validator {
+
+ @Override
+ public boolean supports(Class> clazz) {
+ return false;
+ }
+
+ @Override
+ public void validate(Object target, Errors errors) {
+ }
+}
diff --git a/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigvalidation/MyController.java b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigvalidation/MyController.java
new file mode 100644
index 000000000000..0214a63ffcec
--- /dev/null
+++ b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigvalidation/MyController.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigvalidation;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.WebDataBinder;
+import org.springframework.web.bind.annotation.InitBinder;
+
+// tag::snippet[]
+@Controller
+public class MyController {
+
+ @InitBinder
+ public void initBinder(WebDataBinder binder) {
+ binder.addValidators(new FooValidator());
+ }
+}
+// end::snippet[]
diff --git a/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigvalidation/WebConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigvalidation/WebConfiguration.java
new file mode 100644
index 000000000000..8c7d0cb6379a
--- /dev/null
+++ b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigvalidation/WebConfiguration.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigvalidation;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.validation.Validator;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+// tag::snippet[]
+@Configuration
+public class WebConfiguration implements WebMvcConfigurer {
+
+ @Override
+ public Validator getValidator() {
+ // ...
+ }
+}
+// end::snippet[]
diff --git a/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewcontroller/WebConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewcontroller/WebConfiguration.java
new file mode 100644
index 000000000000..f623fda64a6e
--- /dev/null
+++ b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewcontroller/WebConfiguration.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigviewcontroller;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+// tag::snippet[]
+@Configuration
+public class WebConfiguration implements WebMvcConfigurer {
+
+ @Override
+ public void addViewControllers(ViewControllerRegistry registry) {
+ registry.addViewController("/").setViewName("home");
+ }
+}
+// end::snippet[]
+
diff --git a/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewresolvers/FreeMarkerConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewresolvers/FreeMarkerConfiguration.java
new file mode 100644
index 000000000000..0d949748a323
--- /dev/null
+++ b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewresolvers/FreeMarkerConfiguration.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigviewresolvers;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
+import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
+
+// tag::snippet[]
+@Configuration
+public class FreeMarkerConfiguration implements WebMvcConfigurer {
+
+ @Override
+ public void configureViewResolvers(ViewResolverRegistry registry) {
+ registry.enableContentNegotiation(new MappingJackson2JsonView());
+ registry.freeMarker().cache(false);
+ }
+
+ @Bean
+ public FreeMarkerConfigurer freeMarkerConfigurer() {
+ FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
+ configurer.setTemplateLoaderPath("/freemarker");
+ return configurer;
+ }
+}
+// end::snippet[]
\ No newline at end of file
diff --git a/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewresolvers/WebConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewresolvers/WebConfiguration.java
new file mode 100644
index 000000000000..c4d27f555ebd
--- /dev/null
+++ b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewresolvers/WebConfiguration.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigviewresolvers;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
+
+// tag::snippet[]
+@Configuration
+public class WebConfiguration implements WebMvcConfigurer {
+
+ @Override
+ public void configureViewResolvers(ViewResolverRegistry registry) {
+ registry.enableContentNegotiation(new MappingJackson2JsonView());
+ registry.jsp();
+ }
+}
+// end::snippet[]
diff --git a/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcdefaultservlethandler/CustomDefaultServletConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcdefaultservlethandler/CustomDefaultServletConfiguration.java
new file mode 100644
index 000000000000..055263cac89c
--- /dev/null
+++ b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcdefaultservlethandler/CustomDefaultServletConfiguration.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcdefaultservlethandler;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+// tag::snippet[]
+@Configuration
+public class CustomDefaultServletConfiguration implements WebMvcConfigurer {
+
+ @Override
+ public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
+ configurer.enable("myCustomDefaultServlet");
+ }
+}
+// end::snippet[]
diff --git a/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcdefaultservlethandler/WebConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcdefaultservlethandler/WebConfiguration.java
new file mode 100644
index 000000000000..49a110e68096
--- /dev/null
+++ b/framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcdefaultservlethandler/WebConfiguration.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcdefaultservlethandler;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+// tag::snippet[]
+@Configuration
+public class WebConfiguration implements WebMvcConfigurer {
+
+ @Override
+ public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
+ configurer.enable();
+ }
+}
+// end::snippet[]
diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigadvancedjava/WebConfiguration.kt b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigadvancedjava/WebConfiguration.kt
new file mode 100644
index 000000000000..f5ee4887eb8f
--- /dev/null
+++ b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigadvancedjava/WebConfiguration.kt
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigadvancedjava
+
+import org.springframework.context.annotation.Configuration
+import org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration
+
+// tag::snippet[]
+@Configuration
+class WebConfiguration : DelegatingWebMvcConfiguration() {
+
+ // ...
+}
+// end::snippet[]
\ No newline at end of file
diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigadvancedxml/MyPostProcessor.kt b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigadvancedxml/MyPostProcessor.kt
new file mode 100644
index 000000000000..8c74484407fa
--- /dev/null
+++ b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigadvancedxml/MyPostProcessor.kt
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigadvancedxml
+
+import org.springframework.beans.factory.config.BeanPostProcessor
+import org.springframework.stereotype.Component
+
+// tag::snippet[]
+@Component
+class MyPostProcessor : BeanPostProcessor {
+
+ override fun postProcessBeforeInitialization(bean: Any, name: String): Any {
+ // ...
+ }
+}
+// end::snippet[]
diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigcontentnegotiation/WebConfiguration.kt b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigcontentnegotiation/WebConfiguration.kt
new file mode 100644
index 000000000000..50bd075660bf
--- /dev/null
+++ b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigcontentnegotiation/WebConfiguration.kt
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigcontentnegotiation
+
+import org.springframework.context.annotation.Configuration
+import org.springframework.http.MediaType
+import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
+
+// tag::snippet[]
+@Configuration
+class WebConfiguration : WebMvcConfigurer {
+
+ override fun configureContentNegotiation(configurer: ContentNegotiationConfigurer) {
+ configurer.mediaType("json", MediaType.APPLICATION_JSON)
+ configurer.mediaType("xml", MediaType.APPLICATION_XML)
+ }
+}
+// end::snippet[]
\ No newline at end of file
diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigconversion/DateTimeWebConfiguration.kt b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigconversion/DateTimeWebConfiguration.kt
new file mode 100644
index 000000000000..f77e14982ce9
--- /dev/null
+++ b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigconversion/DateTimeWebConfiguration.kt
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigconversion
+
+import org.springframework.context.annotation.Configuration
+import org.springframework.format.FormatterRegistry
+import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
+
+
+// tag::snippet[]
+@Configuration
+class DateTimeWebConfiguration : WebMvcConfigurer {
+
+ override fun addFormatters(registry: FormatterRegistry) {
+ DateTimeFormatterRegistrar().apply {
+ setUseIsoFormat(true)
+ registerFormatters(registry)
+ }
+ }
+}
+// end::snippet[]
\ No newline at end of file
diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigconversion/WebConfiguration.kt b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigconversion/WebConfiguration.kt
new file mode 100644
index 000000000000..534fa04b8cdc
--- /dev/null
+++ b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigconversion/WebConfiguration.kt
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigconversion
+
+import org.springframework.context.annotation.Configuration
+import org.springframework.format.FormatterRegistry
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
+
+// tag::snippet[]
+@Configuration
+class WebConfiguration : WebMvcConfigurer {
+
+ override fun addFormatters(registry: FormatterRegistry) {
+ // ...
+ }
+}
+// end::snippet[]
\ No newline at end of file
diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigcustomize/WebConfiguration.kt b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigcustomize/WebConfiguration.kt
new file mode 100644
index 000000000000..485b9f71e02a
--- /dev/null
+++ b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigcustomize/WebConfiguration.kt
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigcustomize
+
+import org.springframework.context.annotation.Configuration
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
+
+// tag::snippet[]
+@Configuration
+class WebConfiguration : WebMvcConfigurer {
+
+ // Implement configuration methods...
+}
+// end::snippet[]
\ No newline at end of file
diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigenable/WebConfiguration.kt b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigenable/WebConfiguration.kt
new file mode 100644
index 000000000000..5fe920100b57
--- /dev/null
+++ b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigenable/WebConfiguration.kt
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigenable
+
+import org.springframework.context.annotation.Configuration
+import org.springframework.web.servlet.config.annotation.EnableWebMvc
+
+// tag::snippet[]
+@Configuration
+@EnableWebMvc
+class WebConfiguration {
+}
+// end::snippet[]
\ No newline at end of file
diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfiginterceptors/WebConfiguration.kt b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfiginterceptors/WebConfiguration.kt
new file mode 100644
index 000000000000..076636d77738
--- /dev/null
+++ b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfiginterceptors/WebConfiguration.kt
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfiginterceptors
+
+import org.springframework.context.annotation.Configuration
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
+import org.springframework.web.servlet.i18n.LocaleChangeInterceptor
+import org.springframework.web.servlet.theme.ThemeChangeInterceptor
+
+// tag::snippet[]
+@Configuration
+class WebConfiguration : WebMvcConfigurer {
+
+ override fun addInterceptors(registry: InterceptorRegistry) {
+ registry.addInterceptor(LocaleChangeInterceptor())
+ registry.addInterceptor(ThemeChangeInterceptor()).addPathPatterns("/**").excludePathPatterns("/admin/**")
+ }
+}
+// end::snippet[]
\ No newline at end of file
diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigmessageconverters/WebConfiguration.kt b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigmessageconverters/WebConfiguration.kt
new file mode 100644
index 000000000000..12c197a46f51
--- /dev/null
+++ b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigmessageconverters/WebConfiguration.kt
@@ -0,0 +1,25 @@
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigmessageconverters
+
+import com.fasterxml.jackson.module.paramnames.ParameterNamesModule
+import org.springframework.context.annotation.Configuration
+import org.springframework.http.converter.HttpMessageConverter
+import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
+import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
+import java.text.SimpleDateFormat
+
+// tag::snippet[]
+@Configuration
+class WebConfiguration : WebMvcConfigurer {
+
+ override fun configureMessageConverters(converters: MutableList>) {
+ val builder = Jackson2ObjectMapperBuilder()
+ .indentOutput(true)
+ .dateFormat(SimpleDateFormat("yyyy-MM-dd"))
+ .modulesToInstall(ParameterNamesModule())
+ converters.add(MappingJackson2HttpMessageConverter(builder.build()))
+ converters.add(MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build()))
+ }
+}
+// end::snippet[]
\ No newline at end of file
diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigpathmatching/WebConfiguration.kt b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigpathmatching/WebConfiguration.kt
new file mode 100644
index 000000000000..3b992374c493
--- /dev/null
+++ b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigpathmatching/WebConfiguration.kt
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigpathmatching
+
+import org.springframework.context.annotation.Configuration
+import org.springframework.web.bind.annotation.RestController
+import org.springframework.web.method.HandlerTypePredicate
+import org.springframework.web.servlet.config.annotation.PathMatchConfigurer
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
+import org.springframework.web.util.pattern.PathPatternParser
+
+// tag::snippet[]
+@Configuration
+class WebConfiguration : WebMvcConfigurer {
+
+ override fun configurePathMatch(configurer: PathMatchConfigurer) {
+ configurer.addPathPrefix("/api", HandlerTypePredicate.forAnnotation(RestController::class.java))
+ }
+
+ fun patternParser(): PathPatternParser {
+ //...
+ }
+}
+// end::snippet[]
\ No newline at end of file
diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigstaticresources/VersionedConfiguration.kt b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigstaticresources/VersionedConfiguration.kt
new file mode 100644
index 000000000000..5cb39227e946
--- /dev/null
+++ b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigstaticresources/VersionedConfiguration.kt
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigstaticresources
+
+import org.springframework.context.annotation.Configuration
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
+import org.springframework.web.servlet.resource.VersionResourceResolver
+
+// tag::snippet[]
+@Configuration
+class VersionedConfiguration : WebMvcConfigurer {
+
+ override fun addResourceHandlers(registry: ResourceHandlerRegistry) {
+ registry.addResourceHandler("/resources/**")
+ .addResourceLocations("/public/")
+ .resourceChain(true)
+ .addResolver(VersionResourceResolver().addContentVersionStrategy("/**"))
+ }
+}
+// end::snippet[]
\ No newline at end of file
diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigstaticresources/WebConfiguration.kt b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigstaticresources/WebConfiguration.kt
new file mode 100644
index 000000000000..72c91e87f177
--- /dev/null
+++ b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigstaticresources/WebConfiguration.kt
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigstaticresources
+
+import org.springframework.context.annotation.Configuration
+import org.springframework.http.CacheControl
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
+import java.time.Duration
+
+// tag::snippet[]
+@Configuration
+class WebConfiguration : WebMvcConfigurer {
+
+ override fun addResourceHandlers(registry: ResourceHandlerRegistry) {
+ registry.addResourceHandler("/resources/**")
+ .addResourceLocations("/public", "classpath:/static/")
+ .setCacheControl(CacheControl.maxAge(Duration.ofDays(365)))
+ }
+}
+// end::snippet[]
diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigvalidation/MyController.kt b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigvalidation/MyController.kt
new file mode 100644
index 000000000000..6d2522c48d47
--- /dev/null
+++ b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigvalidation/MyController.kt
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigvalidation
+
+import org.springframework.stereotype.Controller
+import org.springframework.web.bind.WebDataBinder
+import org.springframework.web.bind.annotation.InitBinder
+
+// tag::snippet[]
+@Controller
+class MyController {
+
+ @InitBinder
+ fun initBinder(binder: WebDataBinder) {
+ binder.addValidators(FooValidator())
+ }
+}
+// end::snippet[]
\ No newline at end of file
diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigvalidation/WebConfiguration.kt b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigvalidation/WebConfiguration.kt
new file mode 100644
index 000000000000..c0cff1028080
--- /dev/null
+++ b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigvalidation/WebConfiguration.kt
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigvalidation
+
+import org.springframework.context.annotation.Configuration
+import org.springframework.validation.Validator
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
+
+// tag::snippet[]
+@Configuration
+class WebConfiguration : WebMvcConfigurer {
+
+ override fun getValidator(): Validator {
+ // ...
+ }
+}
+// end::snippet[]
diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewcontroller/WebConfiguration.kt b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewcontroller/WebConfiguration.kt
new file mode 100644
index 000000000000..69ade9721866
--- /dev/null
+++ b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewcontroller/WebConfiguration.kt
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigviewcontroller
+
+import org.springframework.context.annotation.Configuration
+import org.springframework.web.servlet.config.annotation.ViewControllerRegistry
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
+
+// tag::snippet[]
+@Configuration
+class WebConfiguration : WebMvcConfigurer {
+
+ override fun addViewControllers(registry: ViewControllerRegistry) {
+ registry.addViewController("/").setViewName("home")
+ }
+}
+// end::snippet[]
diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewresolvers/FreeMarkerConfiguration.kt b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewresolvers/FreeMarkerConfiguration.kt
new file mode 100644
index 000000000000..55acaa63cb11
--- /dev/null
+++ b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewresolvers/FreeMarkerConfiguration.kt
@@ -0,0 +1,24 @@
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigviewresolvers
+
+import org.springframework.context.annotation.Bean
+import org.springframework.context.annotation.Configuration
+import org.springframework.web.servlet.config.annotation.ViewResolverRegistry
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
+import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer
+import org.springframework.web.servlet.view.json.MappingJackson2JsonView
+
+// tag::snippet[]
+@Configuration
+class FreeMarkerConfiguration : WebMvcConfigurer {
+
+ override fun configureViewResolvers(registry: ViewResolverRegistry) {
+ registry.enableContentNegotiation(MappingJackson2JsonView())
+ registry.freeMarker().cache(false)
+ }
+
+ @Bean
+ fun freeMarkerConfigurer() = FreeMarkerConfigurer().apply {
+ setTemplateLoaderPath("/freemarker")
+ }
+}
+// end::snippet[]
\ No newline at end of file
diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewresolvers/WebConfiguration.kt b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewresolvers/WebConfiguration.kt
new file mode 100644
index 000000000000..472ecf25bf30
--- /dev/null
+++ b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewresolvers/WebConfiguration.kt
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcconfigviewresolvers
+
+import org.springframework.context.annotation.Configuration
+import org.springframework.web.servlet.config.annotation.ViewResolverRegistry
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
+import org.springframework.web.servlet.view.json.MappingJackson2JsonView
+
+// tag::snippet[]
+@Configuration
+class WebConfiguration : WebMvcConfigurer {
+ override fun configureViewResolvers(registry: ViewResolverRegistry) {
+ registry.enableContentNegotiation(MappingJackson2JsonView())
+ registry.jsp()
+ }
+}
+// end::snippet[]
diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcdefaultservlethandler/CustomDefaultServletConfiguration.kt b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcdefaultservlethandler/CustomDefaultServletConfiguration.kt
new file mode 100644
index 000000000000..648beac23750
--- /dev/null
+++ b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcdefaultservlethandler/CustomDefaultServletConfiguration.kt
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.docs.web.webmvc.mvcconfig.mvcdefaultservlethandler
+
+import org.springframework.context.annotation.Configuration
+import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
+
+// tag::snippet[]
+@Configuration
+class CustomDefaultServletConfiguration : WebMvcConfigurer {
+
+ override fun configureDefaultServletHandling(configurer: DefaultServletHandlerConfigurer) {
+ configurer.enable("myCustomDefaultServlet")
+ }
+}
+// end::snippet[]
diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcdefaultservlethandler/WebConfiguration.kt b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcdefaultservlethandler/WebConfiguration.kt
new file mode 100644
index 000000000000..a217953aa0fd
--- /dev/null
+++ b/framework-docs/src/main/kotlin/org/springframework/docs/web/webmvc/mvcconfig/mvcdefaultservlethandler/WebConfiguration.kt
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2002-2024 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.docs.web.webmvc.mvcconfig.mvcdefaultservlethandler
+
+import org.springframework.context.annotation.Configuration
+import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
+
+// tag::snippet[]
+@Configuration
+class WebConfiguration : WebMvcConfigurer {
+
+ override fun configureDefaultServletHandling(configurer: DefaultServletHandlerConfigurer) {
+ configurer.enable()
+ }
+}
+// end::snippet[]
diff --git a/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigcontentnegotiation/WebConfiguration.xml b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigcontentnegotiation/WebConfiguration.xml
new file mode 100644
index 000000000000..5faef120118e
--- /dev/null
+++ b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigcontentnegotiation/WebConfiguration.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+ json=application/json
+ xml=application/xml
+
+
+
+
+
\ No newline at end of file
diff --git a/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigconversion/WebConfiguration.xml b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigconversion/WebConfiguration.xml
new file mode 100644
index 000000000000..f0bf33102ad5
--- /dev/null
+++ b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigconversion/WebConfiguration.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigenable/WebConfiguration.xml b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigenable/WebConfiguration.xml
new file mode 100644
index 000000000000..da68dad89ac8
--- /dev/null
+++ b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigenable/WebConfiguration.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfiginterceptors/WebConfiguration.xml b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfiginterceptors/WebConfiguration.xml
new file mode 100644
index 000000000000..2d0f1cae1ead
--- /dev/null
+++ b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfiginterceptors/WebConfiguration.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigmessageconverters/WebConfiguration.xml b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigmessageconverters/WebConfiguration.xml
new file mode 100644
index 000000000000..f63d2aab1ff3
--- /dev/null
+++ b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigmessageconverters/WebConfiguration.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigpathmatching/WebConfiguration.xml b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigpathmatching/WebConfiguration.xml
new file mode 100644
index 000000000000..b19e510a5822
--- /dev/null
+++ b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigpathmatching/WebConfiguration.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigstaticresources/VersionedConfiguration.xml b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigstaticresources/VersionedConfiguration.xml
new file mode 100644
index 000000000000..685b2a4be0c8
--- /dev/null
+++ b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigstaticresources/VersionedConfiguration.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigstaticresources/WebConfiguration.xml b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigstaticresources/WebConfiguration.xml
new file mode 100644
index 000000000000..24883846eddd
--- /dev/null
+++ b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigstaticresources/WebConfiguration.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigvalidation/WebConfiguration.xml b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigvalidation/WebConfiguration.xml
new file mode 100644
index 000000000000..782b3cadce80
--- /dev/null
+++ b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigvalidation/WebConfiguration.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewcontroller/WebConfiguration.xml b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewcontroller/WebConfiguration.xml
new file mode 100644
index 000000000000..097ca62890c5
--- /dev/null
+++ b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewcontroller/WebConfiguration.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
diff --git a/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewresolvers/FreeMarkerConfiguration.xml b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewresolvers/FreeMarkerConfiguration.xml
new file mode 100644
index 000000000000..d019b5533535
--- /dev/null
+++ b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewresolvers/FreeMarkerConfiguration.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewresolvers/WebConfiguration.xml b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewresolvers/WebConfiguration.xml
new file mode 100644
index 000000000000..f6dba12f1f1f
--- /dev/null
+++ b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewresolvers/WebConfiguration.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcdefaultservlethandler/CustomDefaultServletConfiguration.xml b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcdefaultservlethandler/CustomDefaultServletConfiguration.xml
new file mode 100644
index 000000000000..d6ae9519abfc
--- /dev/null
+++ b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcdefaultservlethandler/CustomDefaultServletConfiguration.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
diff --git a/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcdefaultservlethandler/WebConfiguration.xml b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcdefaultservlethandler/WebConfiguration.xml
new file mode 100644
index 000000000000..a00ad1073ae7
--- /dev/null
+++ b/framework-docs/src/main/resources/org/springframework/docs/web/webmvc/mvcconfig/mvcdefaultservlethandler/WebConfiguration.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+