title: How to configure Spring MVC with pure Java-based configuration?
body: <p>I have, what I would consider a pretty simple Spring MVC setup. My applicationContext.xml is this:</p>
  
  <pre><code>&lt;mvc:annotation-driven /&gt;
  &lt;mvc:resources mapping="/css/**" location="/css/" /&gt;
  &lt;context:property-placeholder location="classpath:controller-test.properties" /&gt;
  &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
      p:prefix="/WEB-INF/views/" p:suffix=".jsp" /&gt;
  </code></pre>
  
  <p>My web.xml is currently this:</p>
  
  <pre><code>  &lt;servlet&gt;
     &lt;servlet-name&gt;springDispatcherServlet&lt;/servlet-name&gt;
     &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
     &lt;init-param&gt;
        &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
        &lt;param-value&gt;classpath:applicationContext.xml&lt;/param-value&gt;
     &lt;/init-param&gt;
     &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
  
    &lt;!-- Map all requests to the DispatcherServlet for handling --&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;springDispatcherServlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>I am trying to convert this set up to pure Java-based config. I've searched the web and so far, I've come up with stuff that explains (some what) how to do the Java config but doesn't explain how to register that Java config with the environment, i.e., the web context.</p>
  
  <p>What I have so far in terms of @Configuration is this:</p>
  
  <pre><code> @Configuration
   @EnableWebMvc
   @PropertySource("classpath:controller.properties")
   @ComponentScan("com.project.web")
   public class WebSpringConfig extends WebMvcConfigurerAdapter {
  
   @Override
   public void addResourceHandlers(ResourceHandlerRegistry registry) {
      registry.addResourceHandler("/css/**").addResourceLocations("/css/");
   }
  
   @Bean
   public ViewResolver configureViewResolver() {
       InternalResourceViewResolver viewResolve = new InternalResourceViewResolver();
       viewResolve.setPrefix("/WEB-INF/views/");
       viewResolve.setSuffix(".jsp");
  
       return viewResolve;
   }
  
   @Override
   public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer){
     configurer.enable();
   }
  }
  </code></pre>
  
  <p>How do I register this with the web container? I am using the latest spring (4.02).</p>
  
  <p>Thanks!</p>