|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |
@Retention(value=RUNTIME) @Target(value=TYPE) @Documented @Import(value=org.springframework.web.servlet.config.annotation.WebMvcConfiguration.class) public @interface EnableWebMvc
Enables default Spring MVC configuration and registers Spring MVC infrastructure components expected by the
DispatcherServlet
. To use this annotation simply place it on an application @Configuration
class
and that will in turn import default Spring MVC configuration including support for annotated methods
in @Controller
classes.
@Configuration @EnableWebMvc @ComponentScan( basePackageClasses = { MyConfiguration.class }, excludeFilters = { @Filter(type = FilterType.ANNOTATION, value = Configuration.class) } ) public class MyConfiguration { }
To customize the imported configuration you simply implement WebMvcConfigurer
, or more likely extend
WebMvcConfigurerAdapter
overriding selected methods only. The most obvious place to do this is
the @Configuration
class that enabled the Spring MVC configuration via @EnableWebMvc
.
However any @Configuration
class and more generally any Spring bean can implement WebMvcConfigurer
to be detected and given an opportunity to customize Spring MVC configuration at startup.
@Configuration @EnableWebMvc @ComponentScan( basePackageClasses = { MyConfiguration.class }, excludeFilters = { @Filter(type = FilterType.ANNOTATION, value = Configuration.class) } ) public class MyConfiguration extends WebMvcConfigurerAdapter { @Override public void registerFormatters(FormatterRegistry formatterRegistry) { formatterRegistry.addConverter(new MyConverter()); } @Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { converters.add(new MyHttpMessageConverter()); } ... }
WebMvcConfigurer
,
WebMvcConfigurerAdapter
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |