Skip to content

Commit 3c649a6

Browse files
committed
Polish @EnableWebMvc javadoc
1 parent 313ba39 commit 3c649a6

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,15 @@
2828
import org.springframework.web.servlet.HandlerExceptionResolver;
2929

3030
/**
31-
* A variant of {@link WebMvcConfigurationSupport} that delegates to one or more registered
32-
* {@link WebMvcConfigurer}s allowing each of them to customize the default Spring MVC
33-
* code-based configuration.
31+
* A sub-class of {@link WebMvcConfigurationSupport} that detects beans of
32+
* type {@link WebMvcConfigurer}. Each {@link WebMvcConfigurer} is given a
33+
* chance to customize the Spring MVC configuration provided through
34+
* {@link WebMvcConfigurationSupport}.
3435
*
35-
* <p>This class is automatically imported when @{@link EnableWebMvc} is used to annotate
36-
* an @{@link Configuration} class. In turn it detects implementations of {@link WebMvcConfigurer}
37-
* via autowiring and delegates to them.
38-
*
39-
* @see EnableWebMvc
40-
* @see WebMvcConfigurer
41-
*
4236
* @author Rossen Stoyanchev
4337
* @since 3.1
38+
*
39+
* @see EnableWebMvc
4440
*/
4541
@Configuration
4642
public class DelegatingWebMvcConfiguration extends WebMvcConfigurationSupport {

org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/EnableWebMvc.java

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,27 @@
1818
import java.lang.annotation.RetentionPolicy;
1919
import java.lang.annotation.Target;
2020

21-
import org.springframework.context.annotation.Configuration;
2221
import org.springframework.context.annotation.Import;
23-
import org.springframework.web.servlet.DispatcherServlet;
2422

2523
/**
26-
* Enables default Spring MVC configuration and registers Spring MVC infrastructure components expected by the
27-
* {@link DispatcherServlet}. Use this annotation on an @{@link Configuration} class. In turn that will
28-
* import {@link DelegatingWebMvcConfiguration}, which provides default Spring MVC configuration.
24+
* Add this annotation to an {@code @Configuration} class to have the Spring MVC
25+
* configuration defined in {@link WebMvcConfigurationSupport} imported:
26+
*
2927
* <pre class="code">
3028
* &#064;Configuration
3129
* &#064;EnableWebMvc
3230
* &#064;ComponentScan(
3331
* basePackageClasses = { MyConfiguration.class },
3432
* excludeFilters = { @Filter(type = FilterType.ANNOTATION, value = Configuration.class) }
3533
* )
36-
* public class MyConfiguration {
34+
* public class MyWebConfiguration {
3735
*
3836
* }
3937
* </pre>
40-
* <p>To customize the imported configuration implement {@link WebMvcConfigurer}, or more conveniently extend
41-
* {@link WebMvcConfigurerAdapter} overriding specific methods only. Any @{@link Configuration} class that
42-
* implements {@link WebMvcConfigurer} will be detected by {@link DelegatingWebMvcConfiguration} and given
43-
* an opportunity to customize the default Spring MVC code-based configuration.
38+
* <p>Customize the imported configuration by implementing the
39+
* {@link WebMvcConfigurer} interface or more likely by extending the
40+
* {@link WebMvcConfigurerAdapter} base class and overriding individual methods:
41+
*
4442
* <pre class="code">
4543
* &#064;Configuration
4644
* &#064;EnableWebMvc
@@ -60,7 +58,34 @@
6058
* converters.add(new MyHttpMessageConverter());
6159
* }
6260
*
63-
* // &#064;Override methods ...
61+
* // More overridden methods ...
62+
*
63+
* }
64+
* </pre>
65+
*
66+
* <p>If the customization options of {@link WebMvcConfigurer} do not expose
67+
* something you need to configure, consider removing the {@code @EnableWebMvc}
68+
* annotation and extending directly from {@link WebMvcConfigurationSupport}
69+
* overriding selected {@code @Bean} methods:
70+
*
71+
* <pre class="code">
72+
* &#064;Configuration
73+
* &#064;ComponentScan(
74+
* basePackageClasses = { MyConfiguration.class },
75+
* excludeFilters = { @Filter(type = FilterType.ANNOTATION, value = Configuration.class) }
76+
* )
77+
* public class MyConfiguration extends WebMvcConfigurationSupport {
78+
*
79+
* &#064;Override
80+
* public void addFormatters(FormatterRegistry formatterRegistry) {
81+
* formatterRegistry.addConverter(new MyConverter());
82+
* }
83+
*
84+
* &#064;Bean
85+
* public RequestMappingHandlerAdapter requestMappingHandlerAdapter() {
86+
* // Create or delegate to "super" to create and
87+
* // customize properties of RequestMapingHandlerAdapter
88+
* }
6489
*
6590
* }
6691
* </pre>

org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@
7373
import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver;
7474

7575
/**
76-
* A base class that provides default configuration for Spring MVC applications
77-
* by registering Spring MVC infrastructure components to be detected by the
76+
* A base class that provides configuration for Spring MVC applications
77+
* by registering Spring MVC infrastructure components detected by the
7878
* {@link DispatcherServlet}. An application configuration class is not required
7979
* to extend this class. A more likely place to start is to annotate
8080
* an @{@link Configuration} class with @{@link EnableWebMvc}

0 commit comments

Comments
 (0)