title: How to resolve HTTP 404 status in SpringMVC?
body: <p>After trying to understand what am I doing wrong for almost the whole day I am giving up.
  Seems like everything I found on stackoverflow I tried and yet I can't get it all working.
  I have a simple SpringMVC+Maven+Hibernate tutorial set up and ready in eclipse, the only thing that is left is actually running it and seeing the result :( I keep getting HTTP 404 error whatever links I try. </p>
  
  <p><img src="https://i.stack.imgur.com/IAWyd.png" alt="screen1"></p>
  
  <p><img src="https://i.stack.imgur.com/NaaeB.png" alt="screen2"></p>
  
  <p><img src="https://i.stack.imgur.com/c0Bhr.png" alt="screen3"></p>
  
  <p>Here is my setup:</p>
  
  <p><strong><code>web.xml</code></strong></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;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/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>
  
  <p><strong><code>servlet-context.xml</code></strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &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" xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"&gt; 
  
      &lt;!-- Enable @Controller annotation support --&gt;
      &lt;mvc:annotation-driven /&gt;
  
      &lt;!-- Map simple view name such as "test" into /WEB-INF/test.jsp --&gt;
      &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="prefix" value="/WEB-INF/" /&gt;
          &lt;property name="suffix" value=".jsp" /&gt;
      &lt;/bean&gt;
  
      &lt;!-- Scan classpath for annotations (eg: @Service, @Repository etc) --&gt;
      &lt;context:component-scan base-package="com.tutorial.pizzashop"/&gt;
  
      &lt;!-- JDBC Data Source. It is assumed you have MySQL running on localhost port 3306 with 
         username root and blank password. Change below if it's not the case --&gt;
      &lt;bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
          &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"/&gt;
          &lt;property name="url" value="jdbc:mysql://localhost:3306/pizzashop"/&gt; 
          &lt;property name="username" value="root"/&gt;
          &lt;property name="password" value="discover"/&gt;
          &lt;property name="validationQuery" value="SELECT 1"/&gt;
      &lt;/bean&gt;
  
      &lt;!-- Hibernate Session Factory --&gt;
      &lt;bean id="mySessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="myDataSource"/&gt;
          &lt;property name="packagesToScan"&gt;
          &lt;array&gt;
              &lt;value&gt;com.tutorial.pizzashop&lt;/value&gt;
          &lt;/array&gt;
          &lt;/property&gt;
          &lt;property name="hibernateProperties"&gt;
          &lt;value&gt;
              hibernate.dialect=org.hibernate.dialect.MySQLDialect
          &lt;/value&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;!-- Hibernate Transaction Manager --&gt;
      &lt;bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="mySessionFactory"/&gt;
      &lt;/bean&gt;
  
      &lt;!-- Activates annotation based transaction management --&gt;
      &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong><code>index.jsp</code></strong></p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%&gt;
  &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
  &lt;title&gt;Pizzashop&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h1&gt;List of all Pizzas&lt;/h1&gt;
      &lt;ul&gt;
          &lt;c:forEach var="p" items="${pizzas}"&gt;
              &lt;li&gt;${p.id} - ${p.name} : ${p.price}&lt;/li&gt;
          &lt;/c:forEach&gt;
      &lt;/ul&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong><code>PizzaController.java</code></strong></p>
  
  <pre><code>package com.tutorial.pizzashop;
  
  import java.util.List;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  
  @Controller
  @RequestMapping("/")
  public class PizzaController {
      @Autowired
      private PizzaDAO pizzaDAO;
  
      /**
       * This handler method is invoked when http://localhost:8080/pizzashop is
       * requested. The method returns view name "index" which will be resolved
       * into /WEB-INF/index.jsp. See src/main/webapp/WEB-INF/servlet-context.xml
       */
      @RequestMapping(method = RequestMethod.GET)
      public String list(Model model) {
          List&lt;Pizza&gt; pizzas = pizzaDAO.findAll();
          model.addAttribute("pizzas", pizzas);
          return "index";
      }
  }
  </code></pre>
  
  <p><strong><code>PizzaDAO.java</code></strong></p>
  
  <pre><code>package com.tutorial.pizzashop;
  
  import java.util.List;
  
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Repository;
  import org.springframework.transaction.annotation.Transactional;
  
  @Repository
  @SuppressWarnings({ "unchecked", "rawtypes" })
  public class PizzaDAO {
      @Autowired
      private SessionFactory sessionFactory;
  
      /**
       * @Transactional annotation below will trigger Spring Hibernate transaction
       *                manager to automatically create a hibernate session. See
       *                src/main/webapp/WEB-INF/servlet-context.xml
       */
      @Transactional
      public List&lt;Pizza&gt; findAll() {
          Session session = sessionFactory.getCurrentSession();
          List pizzas = session.createQuery("from Pizza").list();
          return pizzas;
      }
  }
  </code></pre>
  
  <p><strong><code>Pizza.java</code></strong></p>
  
  <pre><code>package com.tutorial.pizzashop;
  
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @Entity
  @Table(name = "PIZZAS")
  public class Pizza {
      @Id
      @GeneratedValue
      private long id;
      private String name;
      private double price;
  
  //getters and setters...
  }
  </code></pre>
  
  <p>Tutorial I followed: <a href="http://gerrydevstory.com/2013/06/29/spring-mvc-hibernate-mysql-quick-start-from-scratch/" rel="nofollow noreferrer">http://gerrydevstory.com/2013/06/29/spring-mvc-hibernate-mysql-quick-start-from-scratch/</a></p>