title: Spring MVC - No mapping found for HTTP request with URI [/demo/test] in DispatcherServlet with name 'appServlet'
body: <p>I'm using Spring MVC to create a small web application. When I try to hit a URL that seems to be mapped properly in my controller, I get a 404. I'm trying to hit /projectname/test- and this is what shows in the log when I attempt to do that:</p>
  
  <blockquote>
    <p>WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/demo/test] in DispatcherServlet with name 'appServlet'</p>
  </blockquote>
  
  <p>I've seen a lot of similar questions being asked, but none of the suggested fixes worked for me. I'm using Spring MVC and the server can't seem to resolve the URL coming in through the browser. The strange thing is that "/projectname" works great, but "/projectname/test" won't seem to work at all. The JSPs are all in the same directory (src/main/webapp/WEB-INF/views/) with the following names:</p>
  
  <ul>
  <li>home.jsp</li>
  <li>test.jsp</li>
  <li>userInfo.jsp</li>
  </ul>
  
  <p>Here is my code:</p>
  
  <p>pom.xml:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &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.springapp&lt;/groupId&gt;
   &lt;artifactId&gt;demo&lt;/artifactId&gt;
   &lt;name&gt;demo&lt;/name&gt;
   &lt;packaging&gt;war&lt;/packaging&gt;
   &lt;version&gt;1.0.0-BUILD-SNAPSHOT&lt;/version&gt;
   &lt;properties&gt;
    &lt;java-version&gt;1.6&lt;/java-version&gt;
    &lt;org.springframework-version&gt;3.1.1.RELEASE&lt;/org.springframework-version&gt;
    &lt;org.aspectj-version&gt;1.6.10&lt;/org.aspectj-version&gt;
    &lt;org.slf4j-version&gt;1.6.6&lt;/org.slf4j-version&gt;
   &lt;/properties&gt;
   &lt;dependencies&gt;
    &lt;!-- Spring --&gt;
    &lt;dependency&gt;
     &lt;groupId&gt;org.springframework&lt;/groupId&gt;
     &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
     &lt;version&gt;${org.springframework-version}&lt;/version&gt;
     &lt;exclusions&gt;
      &lt;!-- Exclude Commons Logging in favor of SLF4j --&gt;
      &lt;exclusion&gt;
       &lt;groupId&gt;commons-logging&lt;/groupId&gt;
       &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
       &lt;/exclusion&gt;
     &lt;/exclusions&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;${org.springframework-version}&lt;/version&gt;
    &lt;/dependency&gt;
      
    &lt;!-- AspectJ --&gt;
    &lt;dependency&gt;
     &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
     &lt;artifactId&gt;aspectjrt&lt;/artifactId&gt;
     &lt;version&gt;${org.aspectj-version}&lt;/version&gt;
    &lt;/dependency&gt; 
    
    &lt;!-- Logging --&gt;
    &lt;dependency&gt;
     &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
     &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
     &lt;version&gt;${org.slf4j-version}&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
     &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
     &lt;artifactId&gt;jcl-over-slf4j&lt;/artifactId&gt;
     &lt;version&gt;${org.slf4j-version}&lt;/version&gt;
     &lt;scope&gt;runtime&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
     &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
     &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
     &lt;version&gt;${org.slf4j-version}&lt;/version&gt;
     &lt;scope&gt;runtime&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
     &lt;groupId&gt;log4j&lt;/groupId&gt;
     &lt;artifactId&gt;log4j&lt;/artifactId&gt;
     &lt;version&gt;1.2.15&lt;/version&gt;
     &lt;exclusions&gt;
      &lt;exclusion&gt;
       &lt;groupId&gt;javax.mail&lt;/groupId&gt;
       &lt;artifactId&gt;mail&lt;/artifactId&gt;
      &lt;/exclusion&gt;
      &lt;exclusion&gt;
       &lt;groupId&gt;javax.jms&lt;/groupId&gt;
       &lt;artifactId&gt;jms&lt;/artifactId&gt;
      &lt;/exclusion&gt;
      &lt;exclusion&gt;
       &lt;groupId&gt;com.sun.jdmk&lt;/groupId&gt;
       &lt;artifactId&gt;jmxtools&lt;/artifactId&gt;
      &lt;/exclusion&gt;
      &lt;exclusion&gt;
       &lt;groupId&gt;com.sun.jmx&lt;/groupId&gt;
       &lt;artifactId&gt;jmxri&lt;/artifactId&gt;
      &lt;/exclusion&gt;
     &lt;/exclusions&gt;
     &lt;scope&gt;runtime&lt;/scope&gt;
    &lt;/dependency&gt;
  
    &lt;!-- @Inject --&gt;
    &lt;dependency&gt;
     &lt;groupId&gt;javax.inject&lt;/groupId&gt;
     &lt;artifactId&gt;javax.inject&lt;/artifactId&gt;
     &lt;version&gt;1&lt;/version&gt;
    &lt;/dependency&gt;
      
    &lt;!-- Servlet --&gt;
    &lt;dependency&gt;
     &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
     &lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
     &lt;version&gt;2.5&lt;/version&gt;
     &lt;scope&gt;provided&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
     &lt;groupId&gt;javax.servlet.jsp&lt;/groupId&gt;
     &lt;artifactId&gt;jsp-api&lt;/artifactId&gt;
     &lt;version&gt;2.1&lt;/version&gt;
     &lt;scope&gt;provided&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
     &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
     &lt;artifactId&gt;jstl&lt;/artifactId&gt;
     &lt;version&gt;1.2&lt;/version&gt;
    &lt;/dependency&gt;
   
    &lt;!-- Test --&gt;
    &lt;dependency&gt;
     &lt;groupId&gt;junit&lt;/groupId&gt;
     &lt;artifactId&gt;junit&lt;/artifactId&gt;
     &lt;version&gt;4.7&lt;/version&gt;
     &lt;scope&gt;test&lt;/scope&gt;
    &lt;/dependency&gt;        
   &lt;/dependencies&gt;
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;artifactId&gt;maven-eclipse-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.9&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;additionalProjectnatures&gt;
                          &lt;projectnature&gt;org.springframework.ide.eclipse.core.springnature&lt;/projectnature&gt;
                      &lt;/additionalProjectnatures&gt;
                      &lt;additionalBuildcommands&gt;
                          &lt;buildcommand&gt;org.springframework.ide.eclipse.core.springbuilder&lt;/buildcommand&gt;
                      &lt;/additionalBuildcommands&gt;
                      &lt;downloadSources&gt;true&lt;/downloadSources&gt;
                      &lt;downloadJavadocs&gt;true&lt;/downloadJavadocs&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.5.1&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.6&lt;/source&gt;
                      &lt;target&gt;1.6&lt;/target&gt;
                      &lt;compilerArgument&gt;-Xlint:all&lt;/compilerArgument&gt;
                      &lt;showWarnings&gt;true&lt;/showWarnings&gt;
                      &lt;showDeprecation&gt;true&lt;/showDeprecation&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                  &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;1.2.1&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;mainClass&gt;org.test.int1.Main&lt;/mainClass&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>web.xml:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
  
   &lt;!-- The definition of the Root Spring Container shared by all Servlets and Filters --&gt;
   &lt;context-param&gt;
    &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
    &lt;param-value&gt;/WEB-INF/spring/root-context.xml&lt;/param-value&gt;
   &lt;/context-param&gt;
   
   &lt;!-- Creates the Spring Container shared by all Servlets and Filters --&gt;
   &lt;listener&gt;
    &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
   &lt;/listener&gt;
  
   &lt;!-- Processes application requests --&gt;
   &lt;servlet&gt;
    &lt;servlet-name&gt;appServlet&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;/WEB-INF/spring/appServlet/servlet-context.xml&lt;/param-value&gt;
    &lt;/init-param&gt;
    &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
   &lt;/servlet&gt;
    
   &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/&lt;/url-pattern&gt;
   &lt;/servlet-mapping&gt;
  
  &lt;/web-app&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>servlet-context.xml :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/mvc"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:beans="http://www.springframework.org/schema/beans"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
   &lt;!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --&gt;
   
   &lt;!-- Enables the Spring MVC @Controller programming model --&gt;
   &lt;annotation-driven/&gt;
  
   &lt;!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --&gt;
   &lt;resources mapping="/resources/**" location="/resources/" /&gt;
  
   &lt;!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --&gt;
   &lt;beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
    &lt;beans:property name="prefix" value="/WEB-INF/views/" /&gt;
    &lt;beans:property name="suffix" value=".jsp" /&gt;
   &lt;/beans:bean&gt;
   
   &lt;context:component-scan base-package="com.springapp.demo" /&gt;
   
   
   
  &lt;/beans:beans&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>HomeController.java : </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>package com.springapp.demo;
  
  import java.util.Locale;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RequestParam;
  
  /**
   * Handles requests for the application home page.
   */
  @RequestMapping(value = "/")
  @Controller
  public class HomeController {
   
   private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
   
   /**
    * Simply selects the home view to render by returning its name.
    */
   @RequestMapping(value = "/", method = RequestMethod.GET)
   public String home(Locale locale, Model model) {
    logger.info("Welcome home! The client locale is {}.", locale);
    
    return "home";
   }
   
   @RequestMapping(value = "/user", method = RequestMethod.POST)
   public String userInfo(Model model, @RequestParam(value="userName")String userName, @RequestParam(value="gender")String gender ) {
      
    model.addAttribute("userName", userName);
    model.addAttribute("gender", gender);
    
    return "userInfo";
   }
   @RequestMapping(value = "/test", method = RequestMethod.GET)
   public String test(Model model) {
    
    return "test";
   }
   
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Any ideas? Is there more info I need to provide? Thanks!</p>