title: When to implement WebMvcConfigurer to configure Spring MVC?
body: <p>I'm learning about Spring MVC with Java configuration (no xml) and I have a simple question. I see 2 approaches of making Spring bean configuration:</p>
  
  <p>approach 1:</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  @ComponentScan(basePackages="com.demo.springmvc")
  public class DemoAppConfig {
  
      // define a bean for ViewResolver
  
      @Bean
      public ViewResolver viewResolver() {
  
          InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
  
          viewResolver.setPrefix("/WEB-INF/view/");
          viewResolver.setSuffix(".jsp");
  
          return viewResolver;
      }
  
  }
  </code></pre>
  
  <p>approach 2:</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  @ComponentScan(basePackages = "com.example")
  public class SpringConfig implements WebMvcConfigurer{
  
      @Bean
      public ViewResolver viewResolver() {
          InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
          viewResolver.setViewClass(JstlView.class);
          viewResolver.setPrefix("/WEB-INF/pages/");
          viewResolver.setSuffix(".jsp");
  
          return viewResolver;
      }
  
      @Override
      public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
          configurer.enable();
      }
  
  }
  </code></pre>
  
  <p>So one way is by implementing the WebMvcConfigurer interface and another way in not implementing the WebMvcConfigurer interface. I want to ask you what is the difference? What's happen when I implement this interface and what's happen when I don't implement it. Any feedback will be appreciated.</p>