Tutorial:Create Spring 3 MVC Hibernate 3 Example using Maven in Eclipse

Let us make a complete end-to-end application using Spring 3.0 MVC as front end technology and Hibernate as backend ORM technology. For this application we will also use Maven for build and dependency management and MySQL as database to persist the data.

The application will be a simple Contact Manager app which will allow user to add new contacts. The list of contacts will be displayed and user will be able to delete existing contacts.

Our Goal

As describe above, our goal is to create a contact manager application which will allow the user to add a contact or remove it. The basic requirement of the Contact Manager app will be:

  1. Add new contact in the contact list.
  2. Display all contacts from contact list.
  3. Delete a contact from contact list.

Following is the screenshot of end application.
spring3-hibernate-contact-manager

Application Architecture

We will have a layered architecture for our demo application. The database will be accessed by a Data Access layer popularly called as DAO Layer. This layer will use Hibernate API to interact with database. The DAO layer will be invoked by a service layer. In our application we will have a Service interface called ContactService.
spring3-hibernate-application-architecture

Getting Started

For our Contact Manager example, we will use MySQL database. Create a table contacts in any MySQL database. This is very preliminary example and thus we have minimum columns to represent a contact. Feel free to extend this example and create a more complex application.

CREATE TABLE CONTACTS
(
    id              INT PRIMARY KEY AUTO_INCREMENT,
    firstname    VARCHAR(30),
    lastname    VARCHAR(30),
    telephone   VARCHAR(15),
    email         VARCHAR(30),
    created     TIMESTAMP DEFAULT NOW()
);

Creating Project in Eclipse

The contact manager application will use Maven for build and dependency management. For this we will use the Maven Dynamic Web Project in Eclipse as the base architecture of our application.

Download the below source code:
Maven Dynamic Web Project (6.7 KB)

spring3-hibernate-project-structureUnzip the source code to your hard drive and import the project in Eclipse. Once the project is imported in Eclipse, we will create package structure for Java source. Create following packages under src/main/java folder.

  • net.viralpatel.contact.controller – This package will contain Spring Controller classes for Contact Manager application.
  • net.viralpatel.contact.form – This package will contain form object for Contact manager application. Contact form will be a simple POJO class with different attributes such as firstname, lastname etc.
  • net.viralpatel.contact.service – This package will contain code for service layer for our Contact manager application. The service layer will have one ContactService interface and its corresponding implementation class
  • net.viralpatel.contact.dao – This is the DAO layer of Contact manager application. It consists of ContactDAO interface and its corresponding implementation class. The DAO layer will use Hibernate API to interact with database.

Entity Class – The Hibernate domain class

Let us start with the coding of Contact manager application. First we will create a form object or hibernate POJO class to store contact information. Also this class will be an Entity class and will be linked with CONTACTS table in database.
Create a java class Contact.java under net.viralpatel.contact.form package and copy following code into it.

File: src/main/java/net/viralpatel/contact/form/Contact.java

package net.viralpatel.contact.form;

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

@Entity
@Table(name="CONTACTS")
public class Contact {
    
    @Id
    @Column(name="ID")
    @GeneratedValue
    private Integer id;
    
    @Column(name="FIRSTNAME")
    private String firstname;

    @Column(name="LASTNAME")
    private String lastname;

    @Column(name="EMAIL")
    private String email;
    
    @Column(name="TELEPHONE")
    private String telephone;
    
    
    public String getEmail() {
        return email;
    }
    public String getTelephone() {
        return telephone;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }
    public String getFirstname() {
        return firstname;
    }
    public String getLastname() {
        return lastname;
    }
    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }
    public void setLastname(String lastname) {
        this.lastname = lastname;
    }
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
}

The first thing you’ll notice is that the import statements import from javax.persistence rather than a Hibernate or Spring package. Using Hibernate with Spring, the standard JPA annotations work just as well and that’s what I’m using here.

  • First we’ve annotated the class with @Entity which tells Hibernate that this class represents an object that we can persist.
  • The @Table(name = "CONTACTS") annotation tells Hibernate which table to map properties in this class to. The first property in this class on line 16 is our object ID which will be unique for all events persisted. This is why we’ve annotated it with @Id.
  • The @GeneratedValue annotation says that this value will be determined by the datasource, not by the code.
  • The @Column(name = "FIRSTNAME") annotation is used to map this property to the FIRSTNAME column in the CONTACTS table.

The Data Access (DAO) Layer

The DAO layer of Contact Manager application consist of an interface ContactDAO and its corresponding implementation class ContactDAOImpl. Create following Java files in net.viralpatel.contact.dao package.

File: src/main/java/net/viralpatel/contact/dao/ContactDAO.java

package net.viralpatel.contact.dao;

import java.util.List;

import net.viralpatel.contact.form.Contact;

public interface ContactDAO {
    
    public void addContact(Contact contact);
    public List<Contact> listContact();
    public void removeContact(Integer id);
}

File: src/main/java/net/viralpatel/contact/dao/ContactDAOImpl.java

package net.viralpatel.contact.dao;

import java.util.List;

import net.viralpatel.contact.form.Contact;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class ContactDAOImpl implements ContactDAO {

    @Autowired
    private SessionFactory sessionFactory;

    public void addContact(Contact contact) {
        sessionFactory.getCurrentSession().save(contact);
    }

    public List<Contact> listContact() {

        return sessionFactory.getCurrentSession().createQuery("from Contact")
                .list();
    }

    public void removeContact(Integer id) {
        Contact contact = (Contact) sessionFactory.getCurrentSession().load(
                Contact.class, id);
        if (null != contact) {
            sessionFactory.getCurrentSession().delete(contact);
        }

    }
}

The DAO class in above code ContactDAOImpl implements the data access interface ContactDAO which defines methods such as listContact(), addContact() etc to access data from database.

Note that we have used two Spring annotations @Repository and @Autowired.

Classes marked with annotations are candidates for auto-detection by Spring when using annotation-based configuration and classpath scanning. The @Component annotation is the main stereotype that indicates that an annotated class is a “component”.

The @Repository annotation is yet another stereotype that was introduced in Spring 2.0. This annotation is used to indicate that a class functions as a repository and needs to have exception translation applied transparently on it. The benefit of exception translation is that the service layer only has to deal with exceptions from Spring’s DataAccessException hierarchy, even when using plain JPA in the DAO classes.

Another annotation used in ContactDAOImpl is @Autowired. This is used to autowire the dependency of the ContactDAOImpl on the SessionFactory.

The Service Layer

The Service layer of Contact Manager application consist of an interface ContactService and its corresponding implementation class ContactServiceImpl. Create following Java files in net.viralpatel.contact.service package.

File: src/main/java/net/viralpatel/contact/service/ContactService.java

package net.viralpatel.contact.service;

import java.util.List;

import net.viralpatel.contact.form.Contact;

public interface ContactService {
    
    public void addContact(Contact contact);
    public List<Contact> listContact();
    public void removeContact(Integer id);
}

File: src/main/java/net/viralpatel/contact/service/ContactServiceImpl.java

package net.viralpatel.contact.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.viralpatel.contact.dao.ContactDAO;
import net.viralpatel.contact.form.Contact;

@Service
public class ContactServiceImpl implements ContactService {

    @Autowired
    private ContactDAO contactDAO;
    
    @Transactional
    public void addContact(Contact contact) {
        contactDAO.addContact(contact);
    }

    @Transactional
    public List<Contact> listContact() {

        return contactDAO.listContact();
    }

    @Transactional
    public void removeContact(Integer id) {
        contactDAO.removeContact(id);
    }
}

In above service layer code, we have created an interface ContactService and implemented it in class ContactServiceImpl. Note that we used few Spring annotations such as @Service, @Autowired and @Transactional in our code. These annotations are called Spring stereotype annotations.

The @Service stereotype annotation used to decorate the ContactServiceImpl class is a specialized form of the @Component annotation. It is appropriate to annotate the service-layer classes with @Service to facilitate processing by tools or anticipating any future service-specific capabilities that may be added to this annotation.

Adding Spring MVC Support

Let us add Spring MVC support to our web application.

Update the web.xml file and add servlet mapping for org.springframework.web.servlet.DispatcherServlet. Also note that we have mapped url / with springServlet so all the request are handled by spring.

File: /src/webapp/WEB-INF/web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="WebApp_ID" version="2.5">
	<display-name>Spring3-Hibernate</display-name>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
	</welcome-file-list>
	<servlet>
		<servlet-name>spring</servlet-name>
		<servlet-class>
			org.springframework.web.servlet.DispatcherServlet
		</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>spring</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
</web-app>

Once the web.xml is configured, let us add spring-servlet.xml and jdbc.properties files in /src/main/webapp/WEB-INF folder.
File: /src/main/webapp/WEB-INF/jdbc.properties

jdbc.driverClassName= com.mysql.jdbc.Driver
jdbc.dialect=org.hibernate.dialect.MySQLDialect
jdbc.databaseurl=jdbc:mysql://localhost:3306/ContactManager
jdbc.username=root
jdbc.password=testpass

The jdbc.properties file contains database connection information such as database url, username, password, driver class. You may want to edit the driverclass and dialect to other DB if you are not using MySQL.

Oracle Properties

In case you are using Oracle database, you can modify the jdbc properties and have oracle related dialect and other properties:

jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
jdbc.dialect=org.hibernate.dialect.OracleDialect
jdbc.databaseurl=jdbc:oracle:thin:@127.0.0.1:1525:CustomerDB
jdbc.username=scott
jdbc.password=tiger

File: /src/main/webapp/WEB-INF/spring-servlet.xml

<?xml  version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jee="http://www.springframework.org/schema/jee"
	xmlns:lang="http://www.springframework.org/schema/lang"
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
		http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

	<context:annotation-config />
	<context:component-scan base-package="net.viralpatel.contact" />

	<bean id="jspViewResolver"
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="viewClass"
			value="org.springframework.web.servlet.view.JstlView" />
		<property name="prefix" value="/WEB-INF/jsp/" />
		<property name="suffix" value=".jsp" />
	</bean>

	<bean id="messageSource"
		class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
		<property name="basename" value="classpath:messages" />
		<property name="defaultEncoding" value="UTF-8" />
	</bean>
	<bean id="propertyConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
		p:location="/WEB-INF/jdbc.properties" />

	<bean id="dataSource"
		class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
		p:driverClassName="${jdbc.driverClassName}"
		p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"
		p:password="${jdbc.password}" />


	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="configLocation">
			<value>classpath:hibernate.cfg.xml</value>
		</property>
		<property name="configurationClass">
			<value>org.hibernate.cfg.AnnotationConfiguration</value>
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">${jdbc.dialect}</prop>
				<prop key="hibernate.show_sql">true</prop>
			</props>
		</property>
	</bean>

	<tx:annotation-driven />
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>
</beans>

The spring-servlet.xml file contains different spring mappings such as transaction manager, hibernate session factory bean, data source etc.

  • jspViewResolver bean – This bean defined view resolver for spring mvc. For this bean we also set prefix as “/WEB-INF/jsp/” and suffix as “.jsp”. Thus spring automatically resolves the JSP from WEB-INF/jsp folder and assigned suffix .jsp to it.
  • messageSource bean – To provide Internationalization to our demo application, we defined bundle resource property file called messages.properties in classpath.
    Related: Internationalization in Spring MVC
  • propertyConfigurer bean – This bean is used to load database property file jdbc.properties. The database connection details are stored in this file which is used in hibernate connection settings.
  • dataSource bean – This is the java datasource used to connect to contact manager database. We provide jdbc driver class, username, password etc in configuration.
  • sessionFactory bean – This is Hibernate configuration where we define different hibernate settings. hibernate.cfg.xml is set a config file which contains entity class mappings
  • transactionManager bean – We use hibernate transaction manager to manage the transactions of our contact manager application.

File: /src/main/resources/hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <mapping class="net.viralpatel.contact.form.Contact" />
    </session-factory>
	    
</hibernate-configuration>

File: /src/main/resources/messages_en.properties

label.firstname=First Name
label.lastname=Last Name
label.email=Email
label.telephone=Telephone
label.addcontact=Add Contact

label.menu=Menu
label.title=Contact Manager
label.footer=&copy; ViralPatel.net

Spring MVC Controller

We are almost done with our application. Just add following Spring controller class ContactController.java to net.viralpatel.contact.controller package.

File: /src/main/java/net/viralpatel/contact/controller/ContactController.java

package net.viralpatel.contact.controller;

import java.util.Map;

import net.viralpatel.contact.form.Contact;
import net.viralpatel.contact.service.ContactService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class ContactController {

	@Autowired
	private ContactService contactService;

	@RequestMapping("/index")
	public String listContacts(Map<String, Object> map) {

		map.put("contact", new Contact());
		map.put("contactList", contactService.listContact());

		return "contact";
	}

	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public String addContact(@ModelAttribute("contact")
	Contact contact, BindingResult result) {

		contactService.addContact(contact);

		return "redirect:/index";
	}

	@RequestMapping("/delete/{contactId}")
	public String deleteContact(@PathVariable("contactId")
	Integer contactId) {

		contactService.removeContact(contactId);

		return "redirect:/index";
	}
}

The spring controller defines three methods to manipulate contact manager application.

  • listContacts method – This method uses Service interface ContactServer to fetch all the contact details in our application. It returns an array of contacts. Note that we have mapped request “/index” to this method. Thus Spring will automatically calls this method whenever it encounters this url in request.
  • addContact method – This method adds a new contact to contact list. The contact details are fetched in Contact object using @ModelAttribute annotation. Also note that the request “/add” is mapped with this method. The request method should also be POST. Once the contact is added in contact list using ContactService, we redirect to /index page which in turn calls listContacts() method to display contact list to user.
    Related: Forms in Spring MVC
  • deleteContact method – This methods removes a contact from the contact list. Similar to addContact this method also redirects user to /index page once the contact is removed. One this to note in this method is the way we have mapped request url using @RequestMapping annotation. The url “/delete/{contactId}” is mapped thus whenever user send a request /delete/12, the deleteCotact method will try to delete contact with ID:12.

Finally add following JSP file to WEB-INF/jsp folder.

File: /src/main/webapp/WEB-INF/jsp/contact.jsp

<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
	<title>Spring 3 MVC Series - Contact Manager | viralpatel.net</title>
</head>
<body>

<h2>Contact Manager</h2>

<form:form method="post" action="add.html" commandName="contact">

	<table>
	<tr>
		<td><form:label path="firstname"><spring:message code="label.firstname"/></form:label></td>
		<td><form:input path="firstname" /></td> 
	</tr>
	<tr>
		<td><form:label path="lastname"><spring:message code="label.lastname"/></form:label></td>
		<td><form:input path="lastname" /></td>
	</tr>
	<tr>
		<td><form:label path="email"><spring:message code="label.email"/></form:label></td>
		<td><form:input path="email" /></td>
	</tr>
	<tr>
		<td><form:label path="telephone"><spring:message code="label.telephone"/></form:label></td>
		<td><form:input path="telephone" /></td>
	</tr>
	<tr>
		<td colspan="2">
			<input type="submit" value="<spring:message code="label.addcontact"/>"/>
		</td>
	</tr>
</table>	
</form:form>

	
<h3>Contacts</h3>
<c:if  test="${!empty contactList}">
<table class="data">
<tr>
	<th>Name</th>
	<th>Email</th>
	<th>Telephone</th>
	<th>&nbsp;</th>
</tr>
<c:forEach items="${contactList}" var="contact">
	<tr>
		<td>${contact.lastname}, ${contact.firstname} </td>
		<td>${contact.email}</td>
		<td>${contact.telephone}</td>
		<td><a href="delete/${contact.id}">delete</a></td>
	</tr>
</c:forEach>
</table>
</c:if>

</body>
</html>

Download Source code

Spring3MVC_Hibernate_Maven.zip (16 KB)

That’s All folks

Compile and execute the Contact manager application in Eclipse.
spring3-hibernate-contact-manager

If you read this far, you should follow me on twitter here.



484 Comments

  • Amar 7 December, 2013, 1:04

    Thanks Viral. It is useful.
    in contact.jsp, i dont understand the use of form:label tags used…

    <form:label path="firstname"><spring:message code="label.firstname"/></form:label></td>

    I removed and just used only <spring:message code="label.firstname"/>. I got the same view.
    Could you please explain why form:label is required… IS THERE A SPECIFIC PURPOSE.???
    PLEASE REPLY….

  • jason 10 December, 2013, 18:18

    Why do we need the dao layer and service layer? They are the same.

  • varun 11 December, 2013, 10:22

    HTTP Status 500 – Servlet.init() for servlet spring threw exception

  • Prem 13 December, 2013, 12:03

    Please specify how you have resolved the dependencies step by step because I am getting an error while importing

  • Raja 24 December, 2013, 22:06

    Can you please tell me the dependence jar need to add in class path. I am getting error

  • nitesh 26 December, 2013, 15:40

    please help me i am getting this error

    WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:springemvc' did not find a matching property.
    Dec 26, 2013 3:47:34 PM org.apache.catalina.core.AprLifecycleListener init
    INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:/Program Files/Java/jre6/lib/i386;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Intel\DMIX;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Java\jdk1.6.0_12\BIN
    Could not autowire field: private org.hibernate.SessionFactory net.viralpatel.contact.dao.ContactDAOImpl.sessionFactory; nested exception is java.lang.NoClassDefFoundError: Ljavax/transaction/TransactionManager;
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    )
    	... 61 more
    Caused by: java.lang.ClassNotFoundException: javax.transaction.TransactionManager
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
    	... 77 more
    Dec 26, 2013 3:47:35 PM org.apache.catalina.core.StandardContext loadOnStartup
    
    • Dhananjay 27 December, 2013, 17:49

      I had same issue while development as given in above step.
      This error related to hibernate,i found the error was due to the missing below jar files.
      hibernate-annotations.jar
      hibernate-commons-annotations.jar
      i placed above jar files and issue was resolved.

      Enjoy have a happy coding

      Regards
      DJ

  • Jana 26 December, 2013, 15:56

    Hi viral,
    I am imported this example in my system,while running the project it showing some errors .

    HTTP Status 500 -
    
    type Exception report
    
    message
    
    description The server encountered an internal error () that prevented it from fulfilling this request.
    
    exception
    
    javax.servlet.ServletException: Servlet.init() for servlet spring threw exception
    	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    	org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
    
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contactController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private net.viralpatel.contact.service.ContactService org.springframework.beans.factory.BeanCreationException: Could not autowire field: private net.viralpatel.contact.service.ContactService net.viralpatel.contact.controller.ContactController.contactService; nested exception is org.springframework.beans.factory.BeanCreationException: Error 
    org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
    	org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141)
    	org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:72)
    java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
    	org.springframework.orm.hibernate3.LocalSessionFactoryBean.(LocalSessionFactoryBean.java:189)
    

    can u plz , tell me how to resolve this errors?

    • Dhananjay 27 December, 2013, 17:51

      Hi Jana
      I had same issue while development as given in above step.
      This error is related to hibernate,i found the error was due to the missing below jar files.
      hibernate-annotations.jar
      hibernate-commons-annotations.jar
      i placed above jar files and issue was resolved.
      Enjoy have a happy coding
      Regards
      DJ

      • Jana 30 December, 2013, 14:24

        Hi Dhananjay,
        After adding these two jars ,hibernate-annotations.jar,hibernate-commons-annotations.jar.
        Still am getting the same errors.

    • postit 3 March, 2014, 1:55

      Same problem for me. Did you solve the problem ?

  • mitesh 31 December, 2013, 10:33

    hii viral it has helped me a lot.

    viral u hav shown only deleting the row. can u tell how can we eit and update again. pls tell me it will help me a lot

  • bouazza 5 January, 2014, 11:35

    Why this source code don’t work. normally you must import the project in eclipse and all should work.
    someone have a version that works well??
    thks

  • farouk 9 January, 2014, 0:31

    first thank for ths topic
    i have same probleme about line

    Error occured processing XML ‘org/springframework/transaction/interceptor/TransactionInterceptor’.

    ans yes i have the jar
    spring-tx-3.2.5.RELEASE.jar

  • farouk 9 January, 2014, 1:46

    @Jana and others
    for probleme of
    org/springframework/transaction/interceptor/TransactionInterceptor’.

    you should add the librairie AOPAlliance.jar

    read this article
    http://javaprogrammingtips4u.blogspot.com/2010/04/resolve-javalangnoclassdeffounderror.html

  • Sumit 14 January, 2014, 17:33

    Thanks man !! This demo had been a great help.

  • amit 15 January, 2014, 13:36

    hi viral,

    i am getting error ::::::::

    java.lang.reflect.MalformedParameterizedTypeException.

  • Swadhikar 21 January, 2014, 15:50

    Everything runs fine. But my browser displays only the message:

    “Hello World from Servlet”

  • Sivakumar Subramanian 23 January, 2014, 19:05

    Hi,

    I am not getting the table displayed for “contactList” List in JSP?. In the apache console i am getting the SELECT statement, but the records in the Contact table in Database are not displayed in JSP. Please help me

    Regards
    Siva

  • Andrei 24 January, 2014, 15:38

    Thanks. great tutorial

  • Anshi 27 January, 2014, 14:54

    What are all the requisite jar files for this project?

  • heer 27 January, 2014, 22:01

    WHY WE USE THIS IN OUR FORM

  • Sam 4 February, 2014, 3:13

    The service layer is completely useless, just abstraction heavy cruft. It would probably ONLY be useful for complicated writes, but you should do reads straight from the ORM and not wrap the ORM into a 90s stored procedure style wrapping.

  • Diwakar 7 February, 2014, 16:57

    What about all the jars? How all those jars gets resolved. Please give the details of POM.xml as well? I am new to Maven and I have no idea how to put jars using Maven.

    I followed exactly the same steps as mentioned above. But spring,hibernate jars are missing. Please explain about that as well.

    thanks in advance.

  • pravin 14 February, 2014, 17:13

    I am getting the following error please help me

    HTTP Status 500 – Servlet.init() for servlet appServlet threw exception

  • priyanka 21 February, 2014, 14:40

    your program shows error in pom.xml and in taglibs it also shows an error that is “Can not find the tag library descriptor for “http://www.springframework.org/tags”…
    plz send me the simple program of mvc with hibernate.

  • Karthikaiselvan R 24 February, 2014, 17:15

    Hi Guys,

    This application is working fine. Please look your complete error log in console, you can find some ClassNotFound exceptions. If so, please look for those missing class’s jars in internet and keep it in class path.

    There are almost 5 to 6 jars I have downloaded externally apart from spring provided and Hibernate provided.

    List of downloaded jars(even more need to be downloaded if you still face issue – check ur log and download requried jar – sure it will work):
    ———————————
    org-apache-commons-logging.jar
    aopalliance-1.0.jar
    com.springsource.org.hibernate.annotations-3.3.0.ga.jar
    com.springsource.org.hibernate.annotations.common-3.3.0.ga.jar
    hibernate-jpa-2.0-api-1.0.0.Final.jar

    Thanks to Viral patel for this simple example.

    Regards,
    Karthik

    • sweet hopes 14 March, 2014, 14:14

      hii karthik,

      can you post your pom.xml ? please help me.

  • prince parmar 26 February, 2014, 10:24

    Thanks buddy,you have give be great help

  • Marcelo 4 March, 2014, 11:48

    This is a almost perfect tutorial. I had to give up on it because it wont give the pom.xml and its very hard to figure out all the jars that you have to add as dependencies. Project keeps breaking in lots of exceptions and will never build :(

  • Amit Malyan 7 March, 2014, 19:28

    its working fine but i added following mavan dependency.

    mysql
    mysql-connector-java
    5.1.29

    javax.persistence
    persistence-api
    1.0-rev-1

    org.springframework
    spring-tx
    ${org.springframework-version}

    org.hibernate
    hibernate-core
    3.3.0.SP1

    org.hibernate
    hibernate-annotations
    3.4.0.CR2

    org.springframework
    spring-orm
    ${org.springframework-version}

    com.kenai.nbpwr
    org-apache-commons-dbcp
    1.2.2-201002241055

    javassist
    javassist
    3.12.1.GA

  • Vijay 11 March, 2014, 19:48

    I am getting the following error please help me

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘userController’: Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.accent.service.Userservice com.accent.controller.UserController.u; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.accent.service.Userservice] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
    org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
    org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651)
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:599)
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665)
    org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:518)
    org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:459)
    org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
    javax.servlet.GenericServlet.init(GenericServlet.java:160)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    java.lang.Thread.run(Unknown Source)

    • Vignesh 12 March, 2014, 12:41

      Hi i too have the same error as posted by the above commentor Vijay.
      I included all possible maven dependencies but i still get the followinf error.

      Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.example.spring.dao.ContactDAO com.example.spring.service.ContactServiceImpl.contactDAO; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.example.spring.dao.ContactDAO] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

    • manohar 15 April, 2014, 18:56

      Dear sir, please solve my problem, I m facing such type error-
      org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘contactController’: Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private net.viralpatel.contact.service.ContactService org.springframework.beans.factory.BeanCreationException: Could not autowire field: private net.viralpatel.contact.service.ContactService net.viralpatel.contact.controller.ContactController.contactService; nested exception is org.springframework.beans.factory.BeanCreationException: Error
      org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
      org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141)
      org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:72)
      java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
      org.springframework.orm.hibernate3.LocalSessionFactoryBean.(LocalSessionFactoryBean.java:189)

  • d 13 March, 2014, 15:03

    dear sir, I m getting such types error-
    javax.servlet.ServletException: Servlet.init() for servlet spring threw exception
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
    java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    java.lang.Thread.run(Unknown Source)

    root cause

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sessionFactory’ defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:955)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:901)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:546)
    org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:872)
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
    org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
    org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
    org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
    javax.servlet.GenericServlet.init(GenericServlet.java:160)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
    java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    java.lang.Thread.run(Unknown Source)

  • deep 13 March, 2014, 16:58

    Dear sir, please solve my problem, I m facing such type error-

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sessionFactory’ defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Unable to load class declared as in the configuration:
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1412)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)

  • Ricardo Johannsen 14 March, 2014, 10:12

    Grande tutorial, só tenho uma dúvida, onde tem delete você chama o método delete com via GET, isso é muito perigoso, pois get só deve ser usado quando não houver alteração de estado, existe como remover utilizando ou delete ou post? e para navegar para um registro utilizar PUT?

    @RequestMapping("/delete", method = RequestMethod.DELETE)
        public String deleteContact(Contact contact) { ... }
    

    Parabéns pelo trabalho!

  • Ricardo Johannsen 14 March, 2014, 10:14

    Great tutorial, I have only one question, which has

    <a href="delete/${contact.id}"> delete </ a>

    you call the delete method with GET, this is very dangerous because you only get to be used when there is no change of state, exists as using remove or delete or post? and navigate to a record using PUT?

    @ RequestMapping ("/ delete", method = RequestMethod.DELETE)
         public String DeleteContact (Contact contact) {...}
    

    Congratulations for the work!

  • O Connor 19 March, 2014, 0:09

    Which part of the tutorial shows that we are using Maven?

  • Indra kumar 30 March, 2014, 18:57

    Hi Viral,

    I have import this project in my system and i have run it as u have shown here. i have tried many time but every time i got 404 error. i have checked all path.. everything is up to date. but still i getting this error.. if u have some time then can u help me please….?

    • hamid 7 April, 2014, 4:30

      download the attached completed tutorial and do a diff with any programm of you choice. Go through all files which you have created and you will see the failure. This helped me.

  • Nishi 6 April, 2014, 23:40

    Hello Patel,

    I am currently using STS.So,in this case do I have to add “Spring MVC support” part with my project.If yes,then where do I have to add these files?My last question is how to create jdbc.properties file?

    Thank you,

    Nishi

  • hamid 7 April, 2014, 4:27

    Thanks, works fine.
    A point : If you are doing this under Linux the hibernate dependency version has to be with capital ‘GA’ instead of ‘ga’ :
    3.3.2.GA

  • Cheks 25 April, 2014, 9:55

    Please I want to know why in my my object classes, “import javax.persistence.*” and “import org.springframework.transaction.*” cannot be resolved.

  • uma 25 April, 2014, 17:02

    Pls post ur pom.xml. getting error in pom.xml.

  • Sadique 25 April, 2014, 18:15

    A nice example to consolidate some learnings on Spring and Hibernate. My learnings while recreating this project.

    * Always use the “SAME VERSION” Spring/Hibernate/Other Framework jars from the same release only. Not following this may lead to xsd: schema cannot be read type of errors.

    * The errors in console may be appearing from another already open project. Make sure you are following errors from the very project you are working on.

    * If any issue is faced of type “No mapping found for HTTP request with URI [/SpringMVC-Contact_Manager/] in DispatcherServlet with name ‘spring’”
    THEN you are most likely hitting a wrong URL. OR check and correct your controller file, closely observing the patterns.

    * for a Dynamic Web Project like this, the needed jars are not required in the class path, as long as they are available in the lib folder.

    * Make sure the queries are being fired with the SAME NAME AS THE CLASS NAME for everything related with Hibernate.

    * If there is any doubt about If A Particular File Is NOT Read/Picked From the mentioned Path, place that file directly in the scr folder and test.

  • Jabeen 29 April, 2014, 14:34

    org.hibernate
    hibernate-entitymanager
    3.3.2.GA

    changed the above ga to GA worked well like thank you viral

  • BhanuPrasad 2 May, 2014, 0:29

    Hi I download this project and I import this project into my ecplise but I am getting follwing error any one can reslove my problem..plz

    00:29:16,535 ERROR [DispatcherServlet] Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘contactController’: Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private net.viralpatel.contact.service.ContactService net.viralpatel.contact.controller.ContactController.contactService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [net.viralpatel.contact.service.ContactService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1122)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:599)

  • jabeen 23 May, 2014, 13:23

    anyone tried update method please help

  • NoobTutorials 25 May, 2014, 16:01

    why ppl like you make tutorials without testing it, this not working

    • jabeen 26 May, 2014, 17:23

      It works perfectly you have to correct the pom file.Thanks viral for providing this tutorials..
      Please paste the exceptions whichs you are facing

      • Bhagu 2 June, 2014, 15:23

        The prefix “p” for attribute “p:location” associated with an element type “bean” is not bound.

        • Amarnath 16 July, 2014, 17:39

          xmlns:p=”http://www.springframework.org/schema/p”

          include this in your dispatcher.xml file

      • Bhagu 2 June, 2014, 15:23

        any have solution ????

  • Jimmy Dave 10 June, 2014, 17:01

    Hello, very helpful in learning. please list dependency because i face many problem in attaching compatible dependency with its correct version.

  • amit shrivastava 12 June, 2014, 9:32

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sessionFactory’ defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Unable to load class declared as in the configuration:

  • amit shrivastava 12 June, 2014, 9:35

    Unable to load class declared as in the configuration:
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)

  • David 27 June, 2014, 21:30

    Hi.

    @Autowired
    private ContactService contactService;
    

    in controller breaks all.

    I have used the mvc spring project created by STS 3. Just added the java classes and interface.

    Any idea?

    Thanks

  • Mein 1 July, 2014, 11:12

    hello i cant make this work, anyone have the list of jar files?

    • A. K. M. Golam Sarwar 9 July, 2014, 9:39

      The extra jar files that I used in this code to run:
      1. aopalliance.jar
      2. commons-dbcp-1.4.jar
      3. commons-pool-1.6.jar

      Thanks.

  • A. K. M. Golam Sarwar 9 July, 2014, 9:35

    Thanks a lot. Very nice tutorial. It helped me a lot.

  • praveen kumar 15 July, 2014, 16:25

    Thanks a lot .nice tutorial

    when i am deploying this project i am getting below exception:
    15:03:44,717 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-8) MSC00001: Failed to start service jboss.deployment.unit.”Spring3HibernateMaven.war”.PARSE: org.jboss.msc.service.StartException in service jboss.deployment.unit.”Spring3HibernateMaven.war”.PARSE: Failed to process phase PARSE of deployment “Spring3HibernateMaven.war”
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:121)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [:1.7.0_05]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [:1.7.0_05]
    at java.lang.Thread.run(Thread.java:722) [:1.7.0_05]
    Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: Failed to parse POJO xml ["/C:/jboss-as-web-7.0.2.Final/jboss-as-web-7.0.2.Final/standalone/deployments/Spring3HibernateMaven.war/WEB-INF/lib/netty-3.2.1.Final.jar/META-INF/jboss-beans.xml"]
    at org.jboss.as.pojo.KernelDeploymentParsingProcessor.parseDescriptor(KernelDeploymentParsingProcessor.java:130)
    at org.jboss.as.pojo.KernelDeploymentParsingProcessor.parseDescriptors(KernelDeploymentParsingProcessor.java:104)
    at org.jboss.as.pojo.KernelDeploymentParsingProcessor.deploy(KernelDeploymentParsingProcessor.java:76)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:115)
    … 5 more
    Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[17,1]
    Message: Unexpected element ‘{urn:jboss:bean-deployer:2.0}deployment’
    at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:98)
    at org.jboss.staxmapper.XMLMapperImpl.parseDocument(XMLMapperImpl.java:59)
    at org.jboss.as.pojo.KernelDeploymentParsingProcessor.parseDescriptor(KernelDeploymentParsingProcessor.java:123)
    … 8 more

    15:03:44,721 INFO [org.jboss.as.server.controller] (DeploymentScanner-threads – 2) Deployment of “Spring3HibernateMaven.war” was rolled back with failure message {“Failed services” => {“jboss.deployment.unit.\”Spring3HibernateMaven.war\”.PARSE” => “org.jboss.msc.service.StartException in service jboss.deployment.unit.\”Spring3HibernateMaven.war\”.PARSE: Failed to process phase PARSE of deployment \”Spring3HibernateMaven.war\””}}
    15:03:44,721 INFO [org.jboss.as.controller] (DeploymentScanner-threads – 2) Service status report
    Services which failed to start:
    service jboss.deployment.unit.”Spring3HibernateMaven.war”.PARSE: org.jboss.msc.service.StartException in service jboss.deployment.unit.”Spring3HibernateMaven.war”.PARSE: Failed to process phase PARSE of deployment “Spring3HibernateMaven.war”

    15:03:44,722 ERROR [org.jboss.as.deployment] (DeploymentScanner-threads – 1) {“Composite operation failed and was rolled back. Steps that failed:” => {“Operation step-2″ => {“Failed services” => {“jboss.deployment.unit.\”Spring3HibernateMaven.war\”.PARSE” => “org.jboss.msc.service.StartException in service jboss.deployment.unit.\”Spring3HibernateMaven.war\”.PARSE: Failed to process phase PARSE of deployment \”Spring3HibernateMaven.war\””}}}}
    15:03:44,844 INFO [org.jboss.as.server.deployment] (MSC service thread 1-8) Stopped deployment Spring3HibernateMaven.war in 119ms

Leave a Reply

Your email address will not be published. Required fields are marked *

Note

To post source code in comment, use [code language] [/code] tag, for example:

  • [code java] Java source code here [/code]
  • [code html] HTML here [/code]

Current day month ye@r *