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.




Here is my setup:


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns=""





<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="" xmlns:xsi=""
  xmlns:mvc="" xmlns:beans=""
  xmlns:context="" xmlns:tx=""

    <!-- Enable @Controller annotation support -->
    <mvc:annotation-driven />

    <!-- Map simple view name such as "test" into /WEB-INF/test.jsp -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/" />
        <property name="suffix" value=".jsp" />

    <!-- Scan classpath for annotations (eg: @Service, @Repository etc) -->
    <context:component-scan base-package="com.tutorial.pizzashop"/>

    <!-- 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 -->
    <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/pizzashop"/> 
        <property name="username" value="root"/>
        <property name="password" value="discover"/>
        <property name="validationQuery" value="SELECT 1"/>

    <!-- Hibernate Session Factory -->
    <bean id="mySessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="myDataSource"/>
        <property name="packagesToScan">
        <property name="hibernateProperties">

    <!-- Hibernate Transaction Manager -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="mySessionFactory"/>

    <!-- Activates annotation based transaction management -->
    <tx:annotation-driven transaction-manager="transactionManager"/>


<%@ page language="java" contentType="text/html; charset=UTF-8"
<%@ taglib uri="" prefix="c" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <h1>List of all Pizzas</h1>
        <c:forEach var="p" items="${pizzas}">
            <li>${} - ${} : ${p.price}</li>

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;

public class PizzaController {
    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<Pizza> pizzas = pizzaDAO.findAll();
        model.addAttribute("pizzas", pizzas);
        return "index";

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;

@SuppressWarnings({ "unchecked", "rawtypes" })
public class PizzaDAO {
    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
    public List<Pizza> findAll() {
        Session session = sessionFactory.getCurrentSession();
        List pizzas = session.createQuery("from Pizza").list();
        return pizzas;

package com.tutorial.pizzashop;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Table(name = "PIZZAS")
public class Pizza {
    private long id;
    private String name;
    private double price;

//getters and setters...

Tutorial I followed:

Was it helpful?

Solution 3

I found the reason, as it appears I didn't have any .java files in scr/main/java directory. Instead I had my .javas in src/test/java for some reason. What a stupid mistake. After I moved my .java files to src/main/java, compiled and packaged the .war, I moved my .war to Tomcat webapps directory, restarted the server and was able to run it:)

enter image description here


Your app doesn't appear to be deployed on the root context (/).

Try the URL:


The / that you refer to in your web.xml is the root of the context to which your app is deployed.

I have created spring mvc project with tomcat plugin in github, try this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top