title: No mapping found for HTTP request with URI [/projectname/] in DispatcherServlet with name 'spring-mvc'
body: <p>I am extremely new at Spring Security and am trying to learn it using tutorials. Now my application is giving a 404 error which I am unable to resolve. I tried looking at similar problems but that did not work out too. Can you please help me resolve this? The server shows this error:</p>
  
  <pre><code>No mapping found for HTTP request with URI [/test/] in DispatcherServlet with name 'spring-mvc'
  </code></pre>
  
  <p>The page shows:</p>
  
  <pre><code>HTTP ERROR 404
  
  Problem accessing /test/. Reason:
  
      NOT_FOUND
  </code></pre>
  
  <p>My web.xml:</p>
  
  <pre><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;display-name&gt; TestApp&lt;/display-name&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
  &lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;
          /WEB-INF/spring-security.xml
          /WEB-INF/spring-mvc.xml
      &lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;!-- Spring MVC --&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;spring-mvc&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-security.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;spring-mvc&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;  
  
  &lt;!-- Spring Security Filter --&gt;
      &lt;filter&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
      &lt;/filter&gt;
  
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>My spring-security.xml</p>
  
  <pre><code>&lt;beans:beans xmlns="http://www.springframework.org/schema/security"
  xmlns:beans="http://www.springframework.org/schema/beans" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:mvc="http://www.springframework.org/schema/mvc"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
  http://www.springframework.org/schema/security
  http://www.springframework.org/schema/security/spring-security-4.1.xsd
  http://www.springframework.org/schema/mvc
  http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"&gt;
  
  &lt;http auto-config="true"&gt;
      &lt;intercept-url pattern="/admin**" access="hasRole('ROLE_USER')" /&gt;
      &lt;form-login 
          login-page="/login" 
          default-target-url="/welcome" 
          authentication-failure-url="/login?error" 
          username-parameter="username"
          password-parameter="password" /&gt;
      &lt;logout logout-success-url="/login?logout" /&gt;
      &lt;!-- enable csrf protection --&gt;
      &lt;csrf/&gt;
  &lt;/http&gt;
  
  &lt;authentication-manager&gt;
      &lt;authentication-provider&gt;
        &lt;user-service&gt;
          &lt;user name="admin" password="admin" authorities="ROLE_USER" /&gt;
        &lt;/user-service&gt;
      &lt;/authentication-provider&gt;
  &lt;/authentication-manager&gt;   
  </code></pre>
  
  <p>
  </p>
  
  <p>DispatcherServlet:</p>
  
  <pre><code>    &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-4.1.xsd  
       http://www.springframework.org/schema/context 
       http://www.springframework.org/schema/context/spring-context-4.1.xsd
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc.xsd"     
      xmlns:context="http://www.springframework.org/schema/context"&gt;
  
      &lt;context:component-scan base-package="com.test.web.controller.*" /&gt;
      &lt;mvc:annotation-driven/&gt;
  
      &lt;bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="prefix" value="/WEB-INF/pages/" /&gt;
          &lt;property name="suffix" value=".jsp" /&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>admin.jsp</p>
  
  <pre><code>  &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&gt;
  &lt;%@page session="true"%&gt;
  &lt;html&gt;
  &lt;body&gt;
      &lt;h1&gt;Title : ${title}&lt;/h1&gt;
      &lt;h1&gt;Message : ${message}&lt;/h1&gt;
  
      &lt;c:url value="/j_spring_security_logout" var="logoutUrl" /&gt;
  
      &lt;!-- csrt for log out--&gt;
      &lt;form action="${logoutUrl}" method="post" id="logoutForm"&gt;
        &lt;input type="hidden" 
          name="${_csrf.parameterName}"
          value="${_csrf.token}" /&gt;
      &lt;/form&gt;
  
      &lt;script&gt;
          function formSubmit() {
              document.getElementById("logoutForm").submit();
          }
      &lt;/script&gt;
  
      &lt;c:if test="${pageContext.request.userPrincipal.name != null}"&gt;
          &lt;h2&gt;
              Welcome : ${pageContext.request.userPrincipal.name} | &lt;a href="javascript:formSubmit()"&gt; Logout&lt;/a&gt;
          &lt;/h2&gt;
      &lt;/c:if&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>hello.jsp</p>
  
  <pre><code>    &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;%@page session="false"%&gt;
  &lt;html&gt;
  &lt;body&gt;
      &lt;h1&gt;Title : ${title}&lt;/h1&gt;   
      &lt;h1&gt;Message : ${message}&lt;/h1&gt;   
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>login.jsp</p>
  
  <pre><code>    &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Login Page&lt;/title&gt;
  &lt;style&gt;
  .error {
      padding: 15px;
      margin-bottom: 20px;
      border: 1px solid transparent;
      border-radius: 4px;
      color: #a94442;
      background-color: #f2dede;
      border-color: #ebccd1;
  }
  
  .msg {
      padding: 15px;
      margin-bottom: 20px;
      border: 1px solid transparent;
      border-radius: 4px;
      color: #31708f;
      background-color: #d9edf7;
      border-color: #bce8f1;
  }
  
  #login-box {
      width: 300px;
      padding: 20px;
      margin: 100px auto;
      background: #fff;
      -webkit-border-radius: 2px;
      -moz-border-radius: 2px;
      border: 1px solid #000;
  }
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body onload='document.loginForm.username.focus();'&gt;
  
      &lt;h1&gt;Spring Security Custom Login Form (XML)&lt;/h1&gt;
  
      &lt;div id="login-box"&gt;
  
          &lt;h2&gt;Login with Username and Password&lt;/h2&gt;
  
          &lt;c:if test="${not empty error}"&gt;
              &lt;div class="error"&gt;${error}&lt;/div&gt;
          &lt;/c:if&gt;
          &lt;c:if test="${not empty msg}"&gt;
              &lt;div class="msg"&gt;${msg}&lt;/div&gt;
          &lt;/c:if&gt;
  
          &lt;form name='loginForm'
            action="&lt;c:url value='j_spring_security_check' /&gt;" method='POST'&gt;
  
            &lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt;User:&lt;/td&gt;
                  &lt;td&gt;&lt;input type='text' name='username' value=''&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Password:&lt;/td&gt;
                  &lt;td&gt;&lt;input type='password' name='password' /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td colspan='2'&gt;&lt;input name="submit" type="submit"
                      value="submit" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
            &lt;/table&gt;
  
            &lt;input type="hidden" name="${_csrf.parameterName}"
              value="${_csrf.token}" /&gt;
  
          &lt;/form&gt;
      &lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>package com.test.web.controller;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.servlet.ModelAndView;
  
  @Controller
  public class HelloController {
  
      @RequestMapping(value = { "/", "/welcome**" }, method = RequestMethod.GET)
      public ModelAndView welcomePage() {
  
          ModelAndView model = new ModelAndView();
          model.addObject("title", "Spring Security Custom Login Form");
          model.addObject("message", "This is welcome page!");
          model.setViewName("hello");
          return model;
  
      }
  
      @RequestMapping(value = "/admin**", method = RequestMethod.GET)
      public ModelAndView adminPage() {
  
          ModelAndView model = new ModelAndView();
          model.addObject("title", "Spring Security Custom Login Form");
          model.addObject("message", "This is protected page!");
          model.setViewName("admin");
  
          return model;
  
      }
  
      //Spring Security see this :
      @RequestMapping(value = "/login", method = RequestMethod.GET)
      public ModelAndView login(
          @RequestParam(value = "error", required = false) String error,
          @RequestParam(value = "logout", required = false) String logout) {
  
          ModelAndView model = new ModelAndView();
          if (error != null) {
              model.addObject("error", "Invalid username and password!");
          }
  
          if (logout != null) {
              model.addObject("msg", "You've been logged out successfully.");
          }
          model.setViewName("login");
  
          return model;
  
      }
  
  }
  </code></pre>