title: Spring 4.1 configuration for static content
body: <p>I am trying to modify Mkyong's Spring 3 MVC and JSON example (<a href="http://www.mkyong.com/spring-mvc/spring-3-mvc-and-json-example/" rel="nofollow">http://www.mkyong.com/spring-mvc/spring-3-mvc-and-json-example/</a>) to work with Spring 4.1.x and allow reaching html files under webapp directory. For 4.0.x <code>&lt;mvc:resources mapping="/*" location="/WEB-INF" /&gt;</code> with <code>servlet-mapping</code> did the trick, but it doesn't work in 4.1.x; <code>http://localhost:8080/SpringMVCRest/index.html</code> gives 404 error. How can I configure it?</p>
  
  <p><strong>pom.xml:</strong></p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;com.mkyong.common&lt;/groupId&gt;
  &lt;artifactId&gt;SpringMVCRest&lt;/artifactId&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  &lt;name&gt;SpringMVC Json Webapp&lt;/name&gt;
  &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
  &lt;properties&gt;
      &lt;spring.version&gt;4.1.5.RELEASE&lt;/spring.version&gt;
      &lt;jackson.version&gt;1.9.10&lt;/jackson.version&gt;
      &lt;jdk.version&gt;1.6&lt;/jdk.version&gt;
  &lt;/properties&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
          &lt;version&gt;${spring.version}&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
          &lt;version&gt;${spring.version}&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
          &lt;version&gt;${spring.version}&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
        &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
        &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
        &lt;version&gt;2.4.3&lt;/version&gt;
      &lt;/dependency&gt;
  
  &lt;/dependencies&gt;
  
  &lt;build&gt;
      &lt;finalName&gt;SpringMVCRest&lt;/finalName&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-eclipse-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.9&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;downloadSources&gt;true&lt;/downloadSources&gt;
                  &lt;downloadJavadocs&gt;false&lt;/downloadJavadocs&gt;
                  &lt;wtpversion&gt;2.0&lt;/wtpversion&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.3.2&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;source&gt;${jdk.version}&lt;/source&gt;
                  &lt;target&gt;${jdk.version}&lt;/target&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>mvc-dispatcher-servlet.xml:</strong></p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="
      http://www.springframework.org/schema/beans     
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-3.0.xsd
      http://www.springframework.org/schema/mvc
      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"&gt;
  
  &lt;context:component-scan base-package="com.mkyong.common.controller" /&gt;
  
  &lt;mvc:annotation-driven /&gt;
  
  &lt;mvc:resources mapping="/*" location="/WEB-INF" /&gt; 
  
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>web.xml:</strong></p>
  
  <pre><code>&lt;web-app id="WebApp_ID" version="2.4"
  xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
  http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;
  
  &lt;display-name&gt;Spring Web MVC Application&lt;/display-name&gt;
  
  &lt;servlet&gt;
      &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>@Controller
  @RequestMapping("/")
  public class JSONController {
  @RequestMapping(value = "/rest/{name}", method = RequestMethod.GET)
  public @ResponseBody
  Shop getShopInJSON(@PathVariable String name) {
      Shop shop = new Shop();
      shop.setName(name);
      shop.setStaffName(new String[] { "mkyong1", "mkyong2" });
      return shop;
      }   
  }
  </code></pre>