Spring MVC Configuration with Hibernate in Eclipse-maven-JQuery-JSON-CRUD

Spring MVC Configuration with Hibernate in Eclipse-maven-JQuery-JSON-CRUD

Most of the people stuck when they are trying to configure Spring MVC project first time and They don’t know about Each of statement or file. What is the purpose of it and How it works. I’ll try to define each of thing in this example

For the Database table mapping with Java Object, I have used Hibernate which is the most famous Object Relational Mapping tool.

In the most of projects an AJAX call is used for web services which returns JSON so we will learn ajax in JQuery too.

I have used many APIs in this project, Instead of including each of individual API in project I have used Maven Software Project Management tool for managing project APIs.


Package Explorer

Spring MVC
Here in Package Explorer, the Project Structure of Spring MVC  is shown each of section is expanded to see each of file with file extension.


FILE: SpringMVC/pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.spring</groupId>
  <artifactId>SpringMVC</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>SpringMVC Maven Webapp</name>
  <url>http://maven.apache.org</url>
  
  <properties>
    <java-version>1.7</java-version>
    <org.springframework-version>4.2.6.RELEASE</org.springframework-version>
 </properties>
 
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
        
    <dependency>
		<groupId>javax.servlet</groupId>
		<artifactId>javax.servlet-api</artifactId>
		<version>3.1.0</version>
	</dependency>
    
    <dependency>
	<groupId>javax.servlet</groupId>
	<artifactId>jstl</artifactId>
	<version>1.2</version>
</dependency>

<!--  -->

<!-- http://mvnrepository.com/artifact/org.springframework/spring-context-support -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>4.2.6.RELEASE</version>
</dependency>


<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-webmvc</artifactId>
	<version>4.2.6.RELEASE</version>
</dependency>

<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-orm</artifactId>
	<version>4.2.6.RELEASE</version>
</dependency>

<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-tx</artifactId>
	<version>4.2.6.RELEASE</version>
</dependency>

<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-web</artifactId>
	<version>4.2.6.RELEASE</version>
</dependency>


<dependency>
	<groupId>commons-dbcp</groupId>
	<artifactId>commons-dbcp</artifactId>
	<version>1.4</version>
</dependency>

<!-- MySQL Server Libraries -->
<!-- <dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId>
	<version>5.1.36</version>
</dependency> -->

<!-- SQL Server 2012 and 2014 Libraries -->
<dependency>
     <groupId>com.microsoft.sqlserver</groupId>
     <artifactId>sqljdbc4</artifactId>
     <version>3.0</version>
</dependency>

<dependency>
	<groupId>org.codehaus.jackson</groupId>
	<artifactId>jackson-mapper-asl</artifactId>
	<version>1.9.10</version>
</dependency>

<dependency>
	<groupId>com.google.code.gson</groupId>
	<artifactId>gson</artifactId>
	<version>2.3</version>
</dependency>

<dependency>
	<groupId>org.hibernate</groupId>
	<artifactId>hibernate-core</artifactId>
	<version>4.1.0.Final</version>
</dependency>


	<dependency>
			<groupId>org.hibernate.javax.persistence</groupId>
			<artifactId>hibernate-jpa-2.0-api</artifactId>
			<version>1.0.0.Final</version>
	</dependency>

<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports</artifactId>
    <version>6.4.0</version>
</dependency>
    
    
  </dependencies>
  <build>
    <finalName>SpringMVC</finalName>
  </build>
</project>

Why we use pom.xml file in spring mvc

POM stands for “Project Object Model”, This is a file which contain all Maven Configuration for building a project.

  • <project> element is the root element of this POM file. There are following possible children of this element with short description.
  • <modelVersion > 4.0.0 is a child element of <project>. It is currently describing the support for Maven 2 and Maven 3 versions.
  • <groupId> is a child element of <project>. It is universally unique identifier for project, as a normal to use fully qualified package name to distinguish similar project names
  • <artifactId> is a child element of <project>. It is a unique identifier within group by the group Id. Artifact Id is produced by Maven for project include JARs, Wars etc.
  • <packaging> is a child element of <project>. If you are running a command “maven clean install” It’ll generate .war file with artifactId. There is in this project we have a name of ArtifactId is SpringMVC so our generated file will be SpringMVC.war in target direct of project.
  • <version> is a child element of <project>. It is a version number of current project.
  • <name> is a child element of <proect>. It is a full name of Project.
  • <url> is a child element of <project>. It is a project’s home page URL.
  • <properties> is a child element of <project>. The various plugins use these project properties.
  • <java-version> is a child element of <properties>. The Java version for plugin use
  • <org.springframework-version> is a child element of <properties>. The Spring frame work version for plugin use.
  • <dependencies> is a child element of <project>. This element describes all dependencies associated with a project. They are automatically downloaded from repositories for this project.
  • <dependency> is a child element of <project>. It is a element for downloading and installing dependency.
  • <groupId> is a child element of <dependency>. It is a unique identifier for  project group, which is produced for dependency.
  • <artifactId> is a child element of <dependency>. It is a unique identifier for artifact.
  • <version> is a child element of <dependency>. It is a version of dependency.

FILE: /SpringMVC/src/main/webapp/index.jsp

<html>
<body>
<h2>Hello World!</h2>
<p>List of URLs for Available Demos</p>
<ul>
	<li><a href="http://localhost:8080/SpringMVC/users/page"> Users CRUD Operations </a></li>
</ul>
</body>
</html>

It is an Index file, which is displayed first and contains Users CURD page URL


FILE: /SpringMVC/src/main/webapp/WEB-INF/applicationContext.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: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-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

<!-- Enable autowire -->
	<context:annotation-config />
 	<context:component-scan base-package="com" />
 	
	<mvc:annotation-driven /> 
	
	<mvc:resources mapping="/resources/**" location="/resources/" />
	
	<!-- If you use MySQL Database comment out this bean and let others commented  -->
    <!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
		<property name="url" value="jdbc:mysql://127.0.0.1:3306/tests" />
		<property name="username" value="root" />
		<property name="password" value="root" />
	</bean> -->
	
	<!-- SQL Server 2012 and 2014 Database drivers and connectivity code -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
		<property name="url" value="jdbc:sqlserver://localhost;databaseName=mydb" />
		<property name="username" value="sa" />
		<property name="password" value="abcd@1234" />
	</bean>

	<!-- Session Factory Declaration -->
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="packagesToScan" value="com.entities" />
		<property name="hibernateProperties">
			<props>
				<!-- SQL Dialect -->
				<!-- <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> -->
				
				<!-- SQL Server 2014 Dialect -->
				<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
				
				<!-- Your required Database Name -->
				<prop key="hibernate.default_schema">dbo</prop>
				
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.enable_lazy_load_no_trans">true</prop>
				<prop key="format_sql">true</prop>
				<prop key="use_sql_comments">true</prop>
			</props>
		</property>
	</bean>

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

</beans>

Why we use application contenxt file in spring mvc?

This fie is used when Spring configuration is provided to Application by application context file. It defines beans at root webapp context.

  • By <context:annotation-config/> element, we tells application to activate beans already registered in application context. It gives general support for annotation Like @Required, @Autowired, @PostConstructor
  • By <context:component-scan base-package=”com”/> element, we tells application to activate beans already registered in application context and scan package to find, register beans in application context.
  • By < mvc:annotation-driven /> element, we gives application to support for annotation-driven MVC Controllers Like @RequestMapping, @Controller, @RequestBody, @ResponseBody
  • By < mvc:resources mapping=”/resources/**” location=”/resources/” /> element,
  • <mvc:annotation-driven /> is to tell that you can define spring beans dependencies without defining much elements in xml or implements interface or extends a class.
  • @Repository is to tell that Class is a Dao without having to extend JpaDaoSupport or SubClass DaoSupport.
  • @Controller is to tell that Class having all methods to handle HTTP request without implements Controller interface or extends Sub class of Controllers.
  • <context:component-scan base-package=”com” /> is to tell that your spring application will search base package for scanning classes with @Controller, @Services, @Repository, or @Component
  • <mvc:resources mapping=”/resources/**” location=”/resources/” /> is tell that spring application needs to define path location and mapping to static resources like CSS, Images or JavaScripts.
  • <bean> is a java bean. Java Bean is a simple class with private fields and setter, getter methods. In XML we can defined it for usage. So here in this file three of beans tags are used with properties. Each property is like Class Private Field.
  • DataSource Bean: There are two attribute defined in this bean.
    • ID is defined for Unique Identifier for this bean as “dataSource”
    • CLASS is defined for reference type of “org.apache.commons.dbcp.BasicDataSource”.
  • BasicDataSource of Apache Commos is used for interaction with Relational Database. It helps for creating a new connection for an application.
  • Properties of BasicDataSource class:
    • driverClassName: The JDBC Driver Class Name to be used.
    • url: The connection URL to be passed to JDBC driver to establish a connection.
    • username: The connection username to be passed to JDBC driver to establish a connection.
    • password: The connection password to be passed to JDBC driver to establish a connection.
  • SessionFactory Bean: There are two attribute defined in this bean.
    • ID Is defined for Unique Identifier for this bean as “sessionFactory”
    • CLASS is defined for reference type of “org.springframework.orm.hibernate4.LocalSessionFactoryBean”.
  • Properties of LocalSessionFactoryBean class:
    • dataSource: SessionFactory uses dataSource properties. There is ref a attribute for referring bean by its ID.
    • packagesToScan: To specify packages to search for auto detection of entity classes in the classpath.
    • hibernateProperties : It sets hibernate properties.
    • hibernate.dialect: To specify correct database Dialect. Each Database has different SQL code generator.
    • hibernate.show_sql: Write all SQL statements to CONSOLE
    • hibernate.default_schema: Qualifies unqualified Table names with Given Table Name and Schema Name.
    • format_sql: Pretty print the SQL in Console and LOG.
    • use_sql_comments: Hibernate will generate Comments inside SQL.
  • TransactionManager Bean: There are two attribute defined in this bean.
    • ID Is defined for Unique Identifier for this bean as “transactionManager”
    • CLASS is defined for reference type of “org.springframework.orm.hibernate4.HibernateTransactionManager”.
  • Properties of HibernateTransactionManager Class:
    This transaction manager is appropriate for applications that use a single Hibernate SessionFactory for transaction data access

FILE:/SpringMVC/src/main/webapp/WEB-INF/SpringMVC-servlet.xml

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

   <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="prefix" value="/WEB-INF/views/" />
      <property name="suffix" value=".jsp" />
   </bean>
 
</beans> 
  • ServletContext.xml: It is a servlet level configuration file. Each application context can have multiple servlet context files. It holds all the configurations for the whole servlet application.
  • InternalResourceViewResolver Bean: By this resolver, we tell the servlet application about path of JSP views under the WEB-INF. Controllers always access them. It takes prefix for the name path and suffix for the file name.

FILE:/SpringMVC/src/main/webapp/WEB-INF/web.xml

<web-app id="WebApp_ID" version="2.4" 
	xmlns="http://java.sun.com/xml/ns/j2ee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
	http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	
  <display-name>Archetype Created Web Application</display-name>
	
	<context-param>
	  	<param-name>ApplicationContext</param-name>
	  	<param-value>/WEB-INF/applicationContext.xml</param-value>
	 </context-param>

  	<servlet>
        <servlet-name>SpringMVC</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>SpringMVC</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	
	<listener>
		<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
	</listener>
	
</web-app>
  • WEB.xml : It is a configuration file for web application in java. It instructs the servlet container (Tomcat) which class to load.
    • Filters could be defined in it.
    • Welcome file list could be defined in it.
    • Error pages could be defined in it.
  • Init-param: It is a static parameter, which is defined within servlet tag.It is a servlet level scope. At the servlet level you can get value of this.
  • Context-param: It is a static parameter, which is defined in web.xml file. It is an application level scope parameter. If the data does not change frequently you can store in it.
  • Servlet: The servlet element contains the declarative data of a servlet.
  • Servlet-Mapping: The servlet-mapping element defines a mapping between a servlet and a URL pattern.
  • Listener: The Listener element defines an event of the web application.

FILE:/SpringMVC/src/main/webapp/WEB-INF/views/users.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Users</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
</head>
<body onload="load();">

		<input type="hidden" id="user_id">
		Name: <input type="text" id="name" required="required" name="user_name"><br>
		Email: <input type="email" id="email" required="required" name="email"><br>
		<button onclick="submit();">Submit</button>
	
	

		<table id="table" border=1>
			<tr> <th> Name </th> <th> Email </th> <th> Edit </th> <th> Delete </th> </tr>
		
		</table>
			
	
	<script type="text/javascript">
	data = "";
	submit = function(){
		 
			$.ajax({
				url:'saveOrUpdate',
				type:'POST',
				data:{user_id:$("#user_id").val(),user_name:$('#name').val(),email:$('#email').val()},
				success: function(response){
						alert(response.message);
						load();		
				}				
			});			
	}
	
	delete_ = function(id){		 
		 $.ajax({
			url:'delete',
			type:'POST',
			data:{user_id:id},
			success: function(response){
					alert(response.message);
					load();
			}				
		});
}
	

	edit = function (index){
		$("#user_id").val(data[index].user_id);
		$("#name").val(data[index].user_name);
		$("#email").val(data[index].email);
		
	}
	
	
	load = function(){	
		$.ajax({
			url:'list',
			type:'POST',
			success: function(response){
					data = response.data;
					$('.tr').remove();
					for(i=0; i<response.data.length; i++){					
						$("#table").append("<tr class='tr'> <td> "+response.data[i].user_name+" </td> <td> "+response.data[i].email+" </td> <td> <a href='#' onclick= edit("+i+");> Edit </a>  </td> </td> <td> <a href='#' onclick='delete_("+response.data[i].user_id+");'> Delete </a>  </td> </tr>");
					}			
			}				
		});
		
	}
		
	</script>
	
</body>
</html>
  • Users.jsp is user-defined page. It is a view for CRUD operations. It contains the javascript functions.
  • Load Function: It loads the data from server sides to the table.
  • Submit Function: It adds new record or updated record.
  • Edit Function: It edit the data to fields.

FILE:/SpringMVC/src/main/java/com/controllers/UsersController.java

Package: com.controllers

package com.controllers;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
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.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.entities.Users;
import com.servicesapi.UsersService;

@Controller
@RequestMapping("users")
public class UsersController {
	
	@Autowired
	UsersService userServices;
	
	@RequestMapping(value="/page", method = RequestMethod.GET)
	public ModelAndView getPage(){
		ModelAndView view =new ModelAndView("users");
		return view;
	}
	
	@RequestMapping(value="/saveOrUpdate", method=RequestMethod.POST)
	public @ResponseBody Map<String,Object> getSaved(Users users){
		Map<String,Object> map = new HashMap<String,Object>();
		
		if(userServices.saveOrUpdate(users)){
			map.put("status","200");
			map.put("message","Your record have been saved successfully");
		}
		
		return map;
	}
	
	
	@RequestMapping(value="/list", method=RequestMethod.POST)
	public @ResponseBody Map<String,Object> getAll(Users users){
		Map<String,Object> map = new HashMap<String,Object>();
	
			List<Users> list = userServices.list();
			
			if (list != null){
				map.put("status","200");
				map.put("message","Data found");
				map.put("data", list);
			}else{
				map.put("status","404");
				map.put("message","Data not found");
				
			}
		
		return map;
	}
	
	
	@RequestMapping(value="/delete", method=RequestMethod.POST)
	public @ResponseBody Map<String,Object> delete(Users users){
		Map<String,Object> map = new HashMap<String,Object>();
		
		if(userServices.delete(users)){
			map.put("status","200");
			map.put("message","Your record have been deleted successfully");
		}
		
		return map;
	}
}

UsersController.java : This is a controller, which receives the http request each time for saveOrEdit record, delete record or retrieving list of records.


FILE:/SpringMVC/src/main/java/com/daoapi/UsersDao .java

Package: com.daoapi

package com.daoapi;

import java.util.List;

import com.entities.Users;

public interface UsersDao {
	public boolean saveOrUpdate(Users users);
	public List<Users> list();
	public boolean delete(Users users);
}

UsersDao: It is a service for Dao repository.


FILE:/SpringMVC/src/main/java/com/daoimpl/UsersImpl .java

Package: com.daoimpl

package com.daoimpl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.ResponseBody;

import com.daoapi.UsersDao;
import com.entities.Users;


@Repository
@Transactional
public class UsersImpl implements UsersDao{

	@Autowired
	SessionFactory session;
	
	public boolean saveOrUpdate(Users users) {
		// TODO Auto-generated method stub
		session.getCurrentSession().saveOrUpdate(users);
		return true;
	}

	public List<Users> list() {
		return session.getCurrentSession().createQuery("from Users").list();
	}

	public boolean delete(Users users) {
		try{
			session.getCurrentSession().delete(users);
		}catch(Exception ex){
			return false;
		}
		
		return true;
	}
	
	
}

UsersDaoImpl: It is a implementation of UsersDao Repository.


FILE:/SpringMVC/src/main/java/com/entities/Users.java

Package: com.entities

package com.entities;

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

@Entity
@Table(name="users")
public class Users {
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="user_id")
	private Integer user_id;
	
	@Column(name="user_name")
	private String user_name;
	
	@Column(name="email")
	private String email;
	
	public Integer getUser_id() {
		return user_id;
	}
	public void setUser_id(Integer user_id) {
		this.user_id = user_id;
	}
	public String getUser_name() {
		return user_name;
	}
	public void setUser_name(String user_name) {
		this.user_name = user_name;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	
}

Users.java: It is an entity class with setter and getter methods.


FILE:/SpringMVC/src/main/java/com/servicesapi/UsersService.java

Package: com.servicesapi

package com.servicesapi;

import java.util.List;

import com.entities.Users;

public interface UsersService {
	public boolean saveOrUpdate(Users users);
	public List<Users> list();
	public boolean delete(Users users);
}

UsersServices: It is a service for Users.


FILE:/SpringMVC/src/main/java/com/servicesimpl/UsersServiceImpl .java

Package: com.servicesimpl

package com.servicesimpl;

import java.util.List;

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

import com.daoapi.UsersDao;
import com.entities.Users;
import com.servicesapi.UsersService;

@Service
public class UsersServiceImpl implements UsersService{

	@Autowired
	UsersDao userDao;
	
	public boolean saveOrUpdate(Users users) {
		return userDao.saveOrUpdate(users);
	}

	public List<Users> list() {
		// TODO Auto-generated method stub
		return userDao.list();
	}

	public boolean delete(Users users) {
		// TODO Auto-generated method stub
		return userDao.delete(users);
	}	
	
}

UsersServicesImpl: It is a service implementation for Users.


If you want watch this tutorial in video, check this Tutorial in Video

Video Tutorials
Video Tutorial

Download Spring MVC Source Code

22 Comments

  1. i don’t where i’m stuck in i contact to you on you web chat room and send you my project trough email,

    i’m facing this problem

    java.lang.ClassNotFoundException: com.springframework.web.servlet.DispatcherServlet
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:511)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:492)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1050)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:989)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4931)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5241)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

    1. Hi, here is Solution for this ERROR.
      Step 1: Right Click On your project name > Properties
      Step 2: Click on Deployment Assembly
      Step 3: Click to Add
      Step 4: Click “Java Build Path Entries”
      Step 5: Click Maven Dependencies
      Step 6: Restart your server
      Now you can enjoy with your code.

  2. hey i got error in this file FILE:/SpringMVC/src/main/webapp/WEB-INF/web.xml
    it says attributes(version , xmlns:xsi,xmln….) must be dexlared !!

  3. While I run this code on server i got ERROR
    HTTP Status 404 – /SpringMVC/

    type Status report

    message /SpringMVC/

    description The requested resource is not available.

    Apache Tomcat/8.0.45

    1. Hi, here is Solution for this ERROR.
      Step 1: Right Click On your project name > Properties
      Step 2: Click on Deployment Assembly
      Step 3: Click to Add
      Step 4: Click “Java Build Path Entries”
      Step 5: Click Maven Dependencies
      Step 6: Restart your server
      Now you can enjoy with your code.

  4. Hi there, Nice Tutorial However While Deploying the Application it is showing error msg.Im sending the error message.

    _________________________________________________________________________________________________________

    Aug 31, 2017 5:10:44 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
    WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ‘source’ to ‘org.eclipse.jst.jee.server:Spring_Hibernate_YouTube_Project’ did not find a matching property.
    Aug 31, 2017 5:10:45 PM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Server version: Apache Tomcat/8.0.43

    1. Hi, here is Solution for this ERROR.
      Step 1: Right Click On your project name > Properties
      Step 2: Click on Deployment Assembly
      Step 3: Click to Add
      Step 4: Click “Java Build Path Entries”
      Step 5: Click Maven Dependencies
      Step 6: Restart your server
      Now you can enjoy with your code.

  5. Hello sir…………..This example is very useful……
    But I need to use HTML …
    so please send me a demo which fetch data from database (mysql) using this design pattern

  6. Thank you for the tutorial. it was helping me a loot. It has been one week since my first time using eclipse. i have follow every step in video and get same problem, the name is undefined and you can fix your problem. but when i tried, i still get stuck, submit button was still not working. How can i fix the issue? Thanks

  7. Type Status Report

    Message /SpringMVC/users/page

    Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

    Apache Tomcat/8.5.28
    i was try to run this project finally am facing this problem pleas and advice
    Step 1: Right Click On your project name > Properties
    Step 2: Click on Deployment Assembly
    Step 3: Click to Add
    Step 4: Click “Java Build Path Entries”
    Step 5: Click Maven Dependencies
    Step 6: Restart your server
    Now you can enjoy with your code.
    i was tried this thing but in my eclips i found Java Build Path Entries but i couldn’t added it

  8. Hello sir,
    Onload data is not showing. It is showing 406 error.
    HTTP Status 406 – Not Acceptable.

    How to resove this error.

  9. Hi,
    I followed your code and everything is ok.
    There is only one problem. I think I am not connected to MySQL.
    When I try to get the list, the status code is 500.. Should I do something on the DB itself? How can I know if I am connected?
    Thanks for your help,
    best regards.

  10. Hi, I followed all your project.
    I have just a problem: saveOrUpdate function
    I noticed that if I try to insert a new user, the ID is null and this cause no action neither on the pagbe nor on the database. If I remove the user_id value from the data, then the insert work but of course I cannote update, because I do not have memory of the ID anymore.
    I do not understand why for you it works. Do you have any idea? Did I miss something?

  11. Hi, I followed all your project.
    I have just a problem: saveOrUpdate function
    I noticed that if I try to insert a new user, the ID is null and this cause no action neither on the pagbe nor on the database. If I remove the user_id value from the data, then the insert work but of course I cannote update, because I do not have memory of the ID anymore.
    I do not understand why for you it works. Do you have any idea? Did I miss something?

  12. Hi Sir,
    video is very helpful for me but when i go through website then not clearly visible due to show coding with content such paragraph tag . Therefore, please improve it will very good for us.

Leave a Reply

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