001/*
002 * Copyright 2002-2016 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.web.servlet.config.annotation;
018
019import java.lang.annotation.Documented;
020import java.lang.annotation.ElementType;
021import java.lang.annotation.Retention;
022import java.lang.annotation.RetentionPolicy;
023import java.lang.annotation.Target;
024
025import org.springframework.context.annotation.Import;
026
027/**
028 * Adding this annotation to an {@code @Configuration} class imports the Spring MVC
029 * configuration from {@link WebMvcConfigurationSupport}, e.g.:
030 *
031 * <pre class="code">
032 * &#064;Configuration
033 * &#064;EnableWebMvc
034 * &#064;ComponentScan(basePackageClasses = { MyConfiguration.class })
035 * public class MyWebConfiguration {
036 *
037 * }
038 * </pre>
039 *
040 * <p>To customize the imported configuration, implement the interface
041 * {@link WebMvcConfigurer} or more likely extend the empty method base class
042 * {@link WebMvcConfigurerAdapter} and override individual methods, e.g.:
043 *
044 * <pre class="code">
045 * &#064;Configuration
046 * &#064;EnableWebMvc
047 * &#064;ComponentScan(basePackageClasses = { MyConfiguration.class })
048 * public class MyConfiguration extends WebMvcConfigurerAdapter {
049 *
050 *         &#064;Override
051 *         public void addFormatters(FormatterRegistry formatterRegistry) {
052 *         formatterRegistry.addConverter(new MyConverter());
053 *         }
054 *
055 *         &#064;Override
056 *         public void configureMessageConverters(List&lt;HttpMessageConverter&lt;?&gt;&gt; converters) {
057 *         converters.add(new MyHttpMessageConverter());
058 *         }
059 *
060 *     // More overridden methods ...
061 * }
062 * </pre>
063 *
064 * <p>If {@link WebMvcConfigurer} does not expose some advanced setting that
065 * needs to be configured, consider removing the {@code @EnableWebMvc}
066 * annotation and extending directly from {@link WebMvcConfigurationSupport}
067 * or {@link DelegatingWebMvcConfiguration}, e.g.:
068 *
069 * <pre class="code">
070 * &#064;Configuration
071 * &#064;ComponentScan(basePackageClasses = { MyConfiguration.class })
072 * public class MyConfiguration extends WebMvcConfigurationSupport {
073 *
074 *         &#064;Override
075 *         public void addFormatters(FormatterRegistry formatterRegistry) {
076 *         formatterRegistry.addConverter(new MyConverter());
077 *         }
078 *
079 *         &#064;Bean
080 *         public RequestMappingHandlerAdapter requestMappingHandlerAdapter() {
081 *         // Create or delegate to "super" to create and
082 *         // customize properties of RequestMappingHandlerAdapter
083 *         }
084 * }
085 * </pre>
086 *
087 * @author Dave Syer
088 * @author Rossen Stoyanchev
089 * @since 3.1
090 * @see org.springframework.web.servlet.config.annotation.WebMvcConfigurer
091 * @see org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
092 * @see org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport
093 * @see org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration
094 */
095@Retention(RetentionPolicy.RUNTIME)
096@Target(ElementType.TYPE)
097@Documented
098@Import(DelegatingWebMvcConfiguration.class)
099public @interface EnableWebMvc {
100}