Skip to content

Commit 8778884

Browse files
committed
Clarify role of WebMvcRegistrations and WebMvcConfigurer
Closes gh-31232
1 parent bf97e6d commit 8778884

File tree

2 files changed

+10
-4
lines changed
  • spring-boot-project

2 files changed

+10
-4
lines changed

Diff for: spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcRegistrations.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.boot.autoconfigure.web.servlet;
1818

1919
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
20+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
2021
import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver;
2122
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
2223
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
@@ -25,9 +26,12 @@
2526
* Interface to register key components of the {@link WebMvcConfigurationSupport} in place
2627
* of the default ones provided by Spring MVC.
2728
* <p>
28-
* All custom instances are later processed by Boot and Spring MVC configurations. A
29-
* single instance of this component should be registered, otherwise making it impossible
30-
* to choose from redundant MVC components.
29+
* All custom instances are later processed by Boot and Spring MVC configurations. To
30+
* participate in, and if desired, override that subsequent processing,
31+
* {@link WebMvcConfigurer} should be used.
32+
* <p>
33+
* A single instance of this component should be registered, otherwise making it
34+
* impossible to choose from redundant MVC components.
3135
*
3236
* @author Brian Clozel
3337
* @since 2.0.0

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

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ In addition to Spring MVC's defaults, the auto-configuration provides the follow
4545
If you want to keep those Spring Boot MVC customizations and make more {spring-framework-docs}/web.html#mvc[MVC customizations] (interceptors, formatters, view controllers, and other features), you can add your own `@Configuration` class of type `WebMvcConfigurer` but *without* `@EnableWebMvc`.
4646

4747
If you want to provide custom instances of `RequestMappingHandlerMapping`, `RequestMappingHandlerAdapter`, or `ExceptionHandlerExceptionResolver`, and still keep the Spring Boot MVC customizations, you can declare a bean of type `WebMvcRegistrations` and use it to provide custom instances of those components.
48+
The custom instances will be subject to further initialization and configuration by Spring MVC.
49+
To participate in, and if desired, override that subsequent processing, a `WebMvcConfigurer` should be used.
4850

4951
If you do not want to use the auto-configuration and want to take complete control of Spring MVC, add your own `@Configuration` annotated with `@EnableWebMvc`.
5052
Alternatively, add your own `@Configuration`-annotated `DelegatingWebMvcConfiguration` as described in the Javadoc of `@EnableWebMvc`.

0 commit comments

Comments
 (0)