What is Spring Framework?
Spring Framework is one of the most popular Java-based application frameworks. Spring framework is an open source java platform and it was created by “Rod Johnson” in 2003. Spring is a complete and modular framework. It means Spring framework can be used for all layer implementations for a real time application or spring can be used for development of particular layer of a real time application unlike struts [only for front end related] and hibernate [only for database related], but with spring we can develop all layers.
Spring framework can be thought of as a framework of frameworks because it provides support to various frameworks such as Struts, Hibernate, EJB, JSF etc. Using web frameworks, we can just develop web applications. Using ORM frameworks we can just develop persistence logics. But using spring framework we can develop all kinds of logics like business logic, persistence logic, integration logic, presentation logic etc. Using spring framework, we can develop all kinds of applications like standalone applications, two-tire applications, web applications, distributed applications and enterprise applications etc. Spring 1.X contains 7 modules, spring 2.X contains 6 modules, and spring 3.X contains 20 modules, but they are grouped into 6 major categories. Spring 1.X overview diagram is as follows
Spring 2.X overview diagram is as follows,
Spring 3.X overview diagram is as follows,
Spring 4.X overview diagram is as follows,
It is fundamental module in Spring Framework; it has provided basic foundation for all other modules of spring framework. This module can be used to prepare Standalone Applications directly. This module is able to provide the features like IOC Containers, Beans, Dependency Injection etc.
AOP Module [Aspect Oriented Programming]
In general, if we prepare enterprise applications by using only Object Orientation then we have to provide both business logic and Services like Transactions, JMS, JAAS etc. in combined manner, it will provide tightly coupled design, it will provide less shareability and less reusability.
In the above context, to improve shareability and Reusability we have to provide loosely coupled design, to get loosely coupled design we have to apply Aspect Oriented Programming. In Aspect Oriented Programming, we will declare each and every service as an aspect and we will inject these aspects in Business Logic at runtime.
The main intention of this module is to interact with database from Spring application in order to perform database operations with JDBC Persistence mechanism. JDBC/DAO modules are able to abstract common JDBC implementation in order to simplify Database interaction from spring applications by providing template classes.
In JDBC, if we want to interact with database then we have to use the following steps
1. Load And Register Driver
2. Establish Connection between Java appl and DB.
Connction conn = DriverManager.getConnection("jdbc: oracle:thin:@localhost:1521:xe", "ashok", "ashok");
3. Create Statement/PreparedStatement/ CallableStatement as per the requirement.
Statement st = conn.createStatement();
4. Write and Execute SQL Queries
ResultSet rs = st.executeQuery("select * from emp");
5. Close the Connection
In the above JDBC Steps, Load and Register Driver, Establish Connection and Create Statement and close the Connection are very common in all the JDBC applications, here Spring JDBC/DAO modules are able to abstract the commonly used steps and giving option to the developers to provided variable part, that is, Executing SQL queries.
Spring DAO and JDBC modules are having their own Exception Classes hierarchy to expose the exception details. Spring DAO/JDBC modules are converting the JDBC generates checked exceptions to Spring defined Unchecked Exceptions by using Exceptions Re-Throwing Mechanism.
ORM Module [Object-Relational Mapping]
The process of mapping Java class with DB table, member variables with table columns and making that java class objects representing DB table rows by having synchronization between them is called ORMapping.
ORM has define a set of rules and regulations to provide mapping between Object Oriented Data Model and Relational Data Model in order to achieve data persistency.
E.g. Hibernate, JPA, Toplink etc.
o prepare Hibernate Application then we have to use the following instructions.
1. Create Configuration class object.
Configuration cfg = new Configuration(); cfg.configure();
2. Create SessionFactory class object
SessionFactory sf = cfg.buildSessionFactory();
3. Create Session object
Session s = sf.openSession();
4. Perform Persistence operations
Object obj = s.load("com.ashok.hibernate.model.Employee.class", 111);
5. Close SessionFactory and Configuration
In the above Hibernate Application steps, Create Configuration class object, Creation SessionFactory object, create Session object and close SessionFactory and Configuration steps are very common in all hibernate applications, in this case, Spring ORM module is able to abstract all the common instructions in order to simplify Data persistence in enterprise applications.
Spring ORM module has provided its own Exceptions hierarchy to expose behalf of the under lying Persistence mechanism like Hibernate, JPA etc. provided checked exceptions.
The main intention of this module to integrate Spring applications with the distributed tech applications like EJBs, RMI etc. it able to get middleware services like JNDI, JTA, JAAS etc. from J2EE.
WEB Module has provided very good environment to integrate other MVC based framework applications like Struts, JSF, XWork2 etc.
WEB-MVC is an MVC implementation provided by Spring framework directly in order to prepare web applications.
Spring Framework has provided its own testing environment to test the enterprise applications by the developers [Unit Testing] in their own way in the form of Test module.
Spring framework has provided Test module right from its Spring3.x version.
Spring Framework has provided Instrumentation API to perform manipulations over the actions which are generated from the .class files without having modifications over the source code.
Spring Framework has provided Messaging module along with its Spring4.x version to provide Messaging Services what JMS is providing previously as part of J2EE.
When we perform any transactions in bank application, we are able to receive mobile updations, in this context, if our mobile device is not ready to receive messages
WEB Module has provided very good environment to integrate other MVC based framework applications like Struts, JSF, XWork2 etc. then we have to keep the respective message in Messaging Container or JMS Server to send the respective message when the target machine / device is ready.