|
18 | 18 | import java.lang.annotation.RetentionPolicy; |
19 | 19 | import java.lang.annotation.Target; |
20 | 20 |
|
21 | | -import org.springframework.context.annotation.Configuration; |
22 | 21 | import org.springframework.context.annotation.Import; |
23 | | -import org.springframework.web.servlet.DispatcherServlet; |
24 | 22 |
|
25 | 23 | /** |
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 | + * |
29 | 27 | * <pre class="code"> |
30 | 28 | * @Configuration |
31 | 29 | * @EnableWebMvc |
32 | 30 | * @ComponentScan( |
33 | 31 | * basePackageClasses = { MyConfiguration.class }, |
34 | 32 | * excludeFilters = { @Filter(type = FilterType.ANNOTATION, value = Configuration.class) } |
35 | 33 | * ) |
36 | | - * public class MyConfiguration { |
| 34 | + * public class MyWebConfiguration { |
37 | 35 | * |
38 | 36 | * } |
39 | 37 | * </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 | + * |
44 | 42 | * <pre class="code"> |
45 | 43 | * @Configuration |
46 | 44 | * @EnableWebMvc |
|
60 | 58 | * converters.add(new MyHttpMessageConverter()); |
61 | 59 | * } |
62 | 60 | * |
63 | | - * // @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 | + * @Configuration |
| 73 | + * @ComponentScan( |
| 74 | + * basePackageClasses = { MyConfiguration.class }, |
| 75 | + * excludeFilters = { @Filter(type = FilterType.ANNOTATION, value = Configuration.class) } |
| 76 | + * ) |
| 77 | + * public class MyConfiguration extends WebMvcConfigurationSupport { |
| 78 | + * |
| 79 | + * @Override |
| 80 | + * public void addFormatters(FormatterRegistry formatterRegistry) { |
| 81 | + * formatterRegistry.addConverter(new MyConverter()); |
| 82 | + * } |
| 83 | + * |
| 84 | + * @Bean |
| 85 | + * public RequestMappingHandlerAdapter requestMappingHandlerAdapter() { |
| 86 | + * // Create or delegate to "super" to create and |
| 87 | + * // customize properties of RequestMapingHandlerAdapter |
| 88 | + * } |
64 | 89 | * |
65 | 90 | * } |
66 | 91 | * </pre> |
|
0 commit comments