What is the Spring framework?
Spring is a lightweight framework. It is an open-source Java Platform which is used for developing robust Java applications very rapidly and easily. Its support is extended to various frameworks such as Struts, Hibernate, EJB, JSF, etc.
Evolution of Spring Framework
Spring Framework was initially developed by Rod Johnson in June 2003. It was first released under the license of Apache 2.0 in the year of 2004. JavaEE application development is made easier by the Spring Framework. XML namespaces and AspectJ support are provided in spring 2.o, Spring 2.5 version provides annotation-driven configuration, Java-based @Configuration model comes under in the version of spring 3.o. With the support for Java 8 and Java EE 7 technologies, the latest version of spring framework 4.o was released. When it comes to size and transparency spring framework is lightweight and weighs around 2 MB
Why Learn Spring?
Spring is one of the most popular application development frameworks for Java Enterprise. So many developers around the world are using Spring Framework for creating high performing, easily testable, and reusable codes for the applications. Any Java application with its core features can be developed easily by using the Spring Framework
Spring Tutorial : Installation guide
1. To download the spring framework you need to visit the official website. Click on the latest framework release to download. Here you will find three files which are shown below:
After downloading the framework check here How to install and configure the Spring Framework and its libraries?
Features of Spring Framework
• POJO Based
• Integration with existing frameworks
• Web MVC.
• Central Exception Handling.
• Lightweight Transaction management
Spring Framework Architecture
The Spring Framework consists of seven modules which are shown in the below Figure. They are named as Spring Core, Spring AOP, Spring Web MVC, Spring DAO, Spring ORM, Spring context, and Spring Web Flow. Each module provides different platforms to develop different enterprise applications such as your Spring Web MVC module is used for developing MVC-based applications.
1. Spring Core Module:
The Spring Core module is the core component of the spring framework, that provides the IoC container .The Spring container is classified into two types of implementations named as
1. Bean factory
2. Application context.
Bean Factory interface acts as a container for beans. It also configures and assembles the dependencies between these objects. The most common implementation of the Bean Factory interface is the XML bean factory class. That allows you to express the object to compose your application and remove the interdependencies between application objects.
2. Spring AOP Module:
Spring AOP module and Object-Oriented Programming (OOP), both are similar, in which they split down the applications into a hierarchy of objects, AOP splits down the programs into aspects. The aspects in Spring AOP, are the regular classes annotated with @Aspect annotation. These aspects help in transaction management and logging and failure monitoring of an application. For example, bank operations such as transferring an amount from one account to another transaction management are required.
3. Spring ORM Module:
For accessing the data from databases in an application the Spring ORM module is used. Spring ORM supports DAO, which provides an easy way to build the DAOs-based ORM solutions that are mentioned below:
• Simple declarative transaction management
• Transparent exception handling
• Thread-safe, lightweight template classes
• DAO support classes
• Resource management
4. Spring Web MVC Module:
The Web MVC module is used for creating Web applications. The Spring Web MVC module separates the code of model and view components of a Web application. In Spring MVC, when a request is generated from the browser, firstly it goes to the Dispatcher Servlet class (Front Controller), that dispatches the request to a controller (Simple Form Controller class or Abstract Wizard form Controller class) using a set of handler mappings. The controller extracts and processes the information embedded in a request and sends it to the result to the Front controller in the form of the model object.
5. Spring Web Flow Module:
This module is an extension of the Spring Web MVC module. Spring Web MVC framework provides form controllers, such as class Simple Form Controller and Abstract Wizard Form Controller class, to implement predefined workflow. The Spring Web Flow defines the XML file that manages the workflow between different pages of a Web application.
6. Spring Web DAO Module:
The DAO package provides DAO support by using data access technologies such as JDBC, Hibernate, or JDO. This module introduces a JDBC abstraction layer by eliminating the need for providing tedious JDBC coding. It also provides programmatic as well as declarative transaction management classes. Heterogeneous Java Database Connectivity and O/R mapping help Spring to work with several data access technologies.
7. Spring Application Context Module:
Application Context is an interface of Bean Factory. It is based on the Core module. It also implements the Message Source interface and provides the messaging functionality to an application.
Spring MVC Architecture (Model-View-Controller)
It is a Java framework that is used to build web applications. It follows the Model-View-Controller design pattern. All the basic features of a core spring framework are implemented by it.
It contains the data of the application. Data can be a single object or a collection of objects.
It contains the business logic of an application. Here, the @Controller annotation is used to mark the class as the controller.
A view represents the provided information in a particular format. Generally, JSP+JSTL is used to create a view page. Although spring also supports other view technologies such as Apache Velocity, Thyme leaf, and Free Marker.
Advantages of using spring framework
1. Use of POJO
2. Ease of Testability
3. Inversion control and API’s
4. Well designed Web-Framework
5. No need to be Reinvent
6. No need of Server
Let’s see some of the disadvantages too.
1. Complexity of spring
2. High Learning curve
3. Tons of parallel mechanisms
4. Lots of XML in spring
5. Lack of Guidelines.
This brings us to the end of this article on Spring Framework. In this spring tutorial you have learnt What is Spring, Architecture of Spring Framework, Features and MVC Architecture. We have also come up with a curriculum that covers exactly what you would need to be expert in Spring Framework Development! You can have a look at the details for Spring course.