Spring

Spring MVC Hibernate MySQL – Multiple Controllers:In our previous example we implemented Spring MVC Hibernate MySQL CRUD Operations (Here). In this article we are going to see how to use Multiple Controllers using Spring MVC.

In the below example, We are going to create 2 entities Employee and Manager and will have separate controllers for both these entities. Let us see how to add, view and delete. Edit operation is same as we discussed in previous example (Here), So i have not implemented Edit operation in this example.

Life Cycle of Bean Factory
In Spring, Bean factory is used to instantiate, configure and manage objects. The objects created by Bean factory are aware of the relationships with other objects. Bean factory also handles the life cycle of objects.

Populate Properties:Bean factory populates all the properties from XML file.

Set Bean Name:
Name of the bean is set, This is done by passing the bean id in XML file to setBeanName() method (from BeanNameAware Interface)

Set Bean Factory:In this step, Bean is given a reference to the bean factory. This is done by method setBeanFactory() from BeanFactoryAware interface.

Pre-Initialization:This performs all the tasks that needs to be performed before the been is initialized. This is done by postProcessBeforeInitialization() method from BeanPostProcessor interface.

Initialize Beans:Performs initializations before bean is ready to be used. Like opening database connections etc.

Post-Initialization:Performs processes that needs to be performed after been is initialized. Method used postProcessAfterInitialization() from BeanPostProcessor interface.

Bean Ready to Use:Bean is ready to use by the application.

Destroy the Bean:Bean is destroyed. Method used is destroy() from DisposableBean interface.

Life Cycle of Application Context:Application context is built over Bean Factory, so application context will inherit all the capabilities of BeanFactory. In addition to that, Application context provides,

Support Internalization

Events to beans, which are registered Listeners

Steps are same as Bean Factory Life Cycle, But it has one Step between SetbeanFactory and Pre-Initialization – SetApplicationContext

This step is only valid if application Context is used. Method used is setApplicationContext() from ApplicationContextAware Interface.

Spring Architecture – An Introduction:Spring is a lightweight framework used to build java applications. In this article let us see the Spring Architecture in detail.

There are seven modules in Spring,

Core

ORM

DAO

AOP

MVC

Application Context

Web Context

CORE:This forms the base of Spring framework. All the other modules are built over Core module. This module contains Bean factory container which forms the basis to implement Dependency Injection.

DAO:Data Access Object – This module provides a standard way for data access. (Hibernate, JDBC etc..). Normally in an application to access the database we need to opening connection, perform the operation and close the connection. But in Spring DAO, We can overcome this issue’s because Spring takes care of opening and closing of database connections and all we have to do write code to perform the operations.

ORM:Object Relational Mapping – This helps us to integrate Spring framework with other Frameworks such as Hibernate, JDO etc.

MVC:Model View Controller – This module helps us to separate application logic from the view.

Application Context:This module is built over Core Module. Application Context has all the concepts of Bean factory and in addition to those concepts application context has internalization of Messages, life cycle events and validation

Web Context:Web Context is a part of web application which includes MVC module.

Spring Hibernate Integration Example – CRUD OperationsIn this article, We are going to see how to perform CRUD Operations with the help of Spring and Hibernate. We are going to use Spring Dependency Injection concept and we are also going to declare Hibernate Properties in Spring Application Context XML file.

I have downloaded and used some jar files in this application,
Jar files Needed:org.apache.commons.dbcp.jarcommons-pool-1.6.jarOther than this, Spring Framework, Hibernate and MySQL JDBC Driver are required