title: HTTP Status 404 - Not Found in Spring 4 application
body: <p>I have NetBeans Spring MVC project without any pom.xml file. I included <strong>jackson-databind-2.7.0-rc1.jar</strong>, <strong>jackson-core-2.7.0-rc1.jar</strong> and <strong>jackson-annotation-2.7.0-rc1.jar</strong>. But I got the following error pressing the button "Click me": <strong>HTTP Status 404 - Not Found</strong>. How can I avoid this error?</p>
  
  <p>Here are my files</p>
  
  <p><strong>applicationContext.xml:</strong></p>
  
  <pre><code>a&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
  &lt;!-- was: &lt;?xml version="1.0" encoding="UTF-8"?&gt; --&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:p="http://www.springframework.org/schema/p"
         xmlns:aop="http://www.springframework.org/schema/aop"
         xmlns:tx="http://www.springframework.org/schema/tx"
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>dispatcher-servlet.xml:</strong></p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
  &lt;!-- was: &lt;?xml version="1.0" encoding="UTF-8"?&gt; --&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:p="http://www.springframework.org/schema/p"
         xmlns:aop="http://www.springframework.org/schema/aop"
         xmlns:tx="http://www.springframework.org/schema/tx"
         xmlns:mvc="http://www.springframework.org/schema/mvc"
         xmlns:context="http://www.springframework.org/schema/context"
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
         http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
      &lt;mvc:annotation-driven/&gt;
      &lt;context:component-scan base-package="controller" /&gt;
  
      &lt;bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/&gt;
  
      &lt;bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"&gt;
          &lt;property name="mappings"&gt;
              &lt;props&gt;
                  &lt;prop key="index.htm"&gt;indexController&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="viewResolver"
            class="org.springframework.web.servlet.view.InternalResourceViewResolver"
            p:prefix="/WEB-INF/jsp/"
            p:suffix=".jsp" /&gt;
  
      &lt;!--
      The index controller.
      --&gt;
      &lt;bean name="indexController"
            class="org.springframework.web.servlet.mvc.ParameterizableViewController"
            p:viewName="index" /&gt;
  
  
      &lt;bean id="viewResolver2" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; 
          &lt;property name="viewClass"  value="org.springframework.web.servlet.view.JstlView" /&gt;  &lt;property name="prefix" value="/WEB-INF/jsp/" /&gt; 
          &lt;property name="suffix" value=".jsp" /&gt; 
      &lt;/bean&gt; 
  
  
       &lt;mvc:resources mapping="/resources/**" location="/resources/"  
      cache-period="31556926"/&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>web.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/applicationContext.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;2&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
          &lt;url-pattern&gt;*.htm&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;session-config&gt;
          &lt;session-timeout&gt;
              30
          &lt;/session-timeout&gt;
      &lt;/session-config&gt;
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;redirect.jsp&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>index.jsp</strong></p>
  
  <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&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;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;Welcome to Spring Web MVC project&lt;/title&gt;
          &lt;script src="&lt;c:url value="/resources/jsgrid/external/jquery/jquery-1.8.3.js" /&gt;"&gt;&lt;/script&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
  
          &lt;script language="javascript"&gt;
  
                  function onClick()
                  {
                       $.ajax({ 
                          type: "GET",
                          dataType: "jsonp",
                          url: "&lt;c:url value="/ls-test.htm" /&gt;",
                          success: function(data){        
                            alert(data);
                          },
                          error: function (data, textStatus, xhr) {
                              $('html').html("" + data.responseText);
                          }
                       });
                  }
              &lt;/script&gt;
  
          &lt;button onclick="onClick()" &gt;Click me&lt;/button&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>example.java</strong></p>
  
  <pre><code>package controller;
  
  import org.springframework.http.HttpStatus;
  import org.springframework.http.MediaType;
  import org.springframework.http.ResponseEntity;
  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.RestController;
  import org.springframework.web.portlet.ModelAndView;
  
  /*
   * To change this license header, choose License Headers in Project Properties.
   * To change this template file, choose Tools | Templates
   * and open the template in the editor.
   */
  
  /**
   *
   * @author 
  */
  @Controller
  public class Example {
  
      class Test
      {
          final int id;
          final String fio;
  
          public Test(int id, String fio) {
              this.id = id;
              this.fio = fio;
          }
  
          public int getId() {
              return id;
          }
  
          public String getFio() {
              return fio;
          }
      }
  
      @RequestMapping(value = "/ls-test", method = RequestMethod.GET,
              produces = {MediaType.APPLICATION_JSON_VALUE})
      public ResponseEntity &lt;Test&gt; test()
      {
          Test t = new Test(1, "123");
  
          return new ResponseEntity&lt;Test&gt;(t, HttpStatus.OK);
      }
  
      @RequestMapping(value = "/index", method = RequestMethod.GET)
      public ModelAndView loadIndex()
      {
          ModelAndView mv = new ModelAndView();
          mv.setViewName("index");
          return mv;
      }
  
  }
  </code></pre>
  
  <p>I have the same error when I chante method test() by the following code:</p>
  
  <pre><code>@RequestMapping(value = "/ls-test", method = RequestMethod.GET,
          produces = {MediaType.APPLICATION_JSON_VALUE})
  public @ResponseBody Test test()
  {
      Test t = new Test(1, "123");
  
      return t;
  }
  </code></pre>