I would like to add resource handlers. In the forum they use WebMvcConfigurationSupport
: http://forum.springsource.org/showthread.php?116068-How-to-configure-lt-mvc-resources-gt-mapping-to-take-precedence-over-RequestMapping&p=384066#post384066
and docs say WebMvcConfigurerAdapter
: http://static.springsource.org/spring/docs/3.2.x/javadoc-api/org/springframework/web/servlet/config/annotation/EnableWebMvc.html
What's the difference and which one to use? Both has the addResourceHandlers
method I need.
This is my current class:
@Configuration @EnableWebMvc public class WebMvcConfig extends WebMvcConfigurerAdapter { public @Override void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/resources/**").addResourceLocations("/resources"); } public @Bean TilesViewResolver tilesViewResolver() { return new TilesViewResolver(); } public @Bean TilesConfigurer tilesConfigurer() { TilesConfigurer ret = new TilesConfigurer(); ret.setDefinitions(new String[] { "classpath:tiles.xml" }); return ret; } }
Interface WebMvcConfigurer. Defines callback methods to customize the Java-based configuration for Spring MVC enabled via @EnableWebMvc . @EnableWebMvc -annotated configuration classes may implement this interface to be called back and given a chance to customize the default configuration.
The @EnableWebMvc annotation is used for enabling Spring MVC in an application and works by importing the Spring MVC Configuration from WebMvcConfigurationSupport.
The answer is in the doc you referenced above:
If the customization options of WebMvcConfigurer do not expose something you need to configure, consider removing the @EnableWebMvc annotation and extending directly from WebMvcConfigurationSupport overriding selected @Bean methods
In short, if @EnableWebMvc works for you, there is no need to look any further.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With