Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between WebMvcConfigurationSupport and WebMvcConfigurerAdapter

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;     } } 
like image 514
dtrunk Avatar asked Jul 27 '13 13:07

dtrunk


People also ask

What is the use of WebMvcConfigurer?

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.

What is EnableWebMvc?

The @EnableWebMvc annotation is used for enabling Spring MVC in an application and works by importing the Spring MVC Configuration from WebMvcConfigurationSupport.


1 Answers

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.

like image 92
Rossen Stoyanchev Avatar answered Oct 10 '22 06:10

Rossen Stoyanchev