Introduction:
Let’s start by understanding what a framework? It specifies the rules for development i.e., provides a restricted environment. The framework manages the plugins and calls them whenever required. It defines the workflow. Libraries are for common tasks and frameworks that deal with common patterns. The framework does not provide full control for developers, Frameworks says that to follow this pattern to make it easy/help for development. Finally, frameworks are simple but less flexible.
Spring Framework:
Spring framework is an open-source light-weight framework. It is the most popularly used framework for developing Java EE applications. In the initial days, When dealing with Java EE applications it was a difficult task to configure and manage and download all the libraries, dependencies, configuring and managing the life cycle of objects for our application.
Initially, the Enterprise Java Bean (EJB) is in use for developing Java EE applications. There were a few problems with EJB:
- Development with EJB requires working with multiple java and XML files and their maintenance was difficult.
- EJB is a heavyweight and mostly depends on the server. There were other few problems so an alternative to EJB, Spring framework has been released.
Spring Framework is simpler because it uses POJO/POJI model. although Spring framework provides various patterns for developing java applications. Spring is not only in use for developing Java EE applications. It can be in use to develop all kinds of java applications.
Spring framework consists of a Spring Application context that manages object instances. Every class declared its required dependencies. Spring looks at declarations and injects dependencies. thus, Spring framework also has a data access API for database connectivity.
however, this framework consists of spring MVC which allows creating web applications and REST API using the spring application model and dependency injection concepts. Spring also has other modules such as spring security, spring cloud, etc. It is simple, flexible, and loosely coupled (IOC).
POJO/POJI:
Plain Old Java Object/Interface is a normal class instance/interface which does not extend prespecified classes or implement interfaces and no prespecified annotations.
Inversion of Control:
It simply means that we need to maintain abstraction or loosely coupled objects, implementation of the object, and construction of an object must be maintained separately. Spring Framework takes care of the object creation and the dependencies of the objects. In a configuration file developer specifies the services needed by components. Then the IOC container is responsible for getting all the services.
Inversion of control is of two types:
- Dependency lookup: It means searching or finding out the dependencies. The first object is responsible.
- Dependency injection: It means injecting or plugging objects to which dependencies are required. Setter Injection and Constructor Injection are types of dependency injection that are supported by spring. Dependency injection is a design pattern.
architecture of Spring Framework:
- Spring framework is a layered architecture.
- It consists of mainly 5 layers.
Spring Core module:
Spring Core module is a collection of Core, Beans, Context, Spring EL modules.
- Bean:
- Bean module deals with creating and managing spring bean objects. It implements a bean factory through factory patterns. BeanFactory interface is defined using the org. spring framework.beans.factory.BeanFactory and acts as a container for beans.
- Core:
- The core module deals with the Spring Inversion of Control (IOC), Dependency Injection concepts.
- Context:
- Context is built based on beans and core. It uses ApplicationContext.
- Spring Expression Language (SpEL):
- Similar to the Java expression language. Here it is used for accessing data and altering object data.
Data-Access/Integration:
- JDBC: This module provides an abstract layer on JDBC and avoids the need for the developer to manually register the application with a database connection.
- ORM: This module provides an abstract layer on ORM tools such as hibernate, JDO which is an implementation of JPA.
- OXM: Responsible for linking Object/XML to XML beans, JAXB etc.
- JMS: Responsible for creating, sending, and receiving messages.
- Transactions: Supports transaction management i.e., ACID properties.
Web (MVC/Remoting):
We can develop MVC applications without any other extra frameworks. We can integrate our spring framework with other frameworks like struts and JSF etc.
Aspect-Oriented Programing:
If business logic and its services are combined the size and complexity increases so in AOP we separate them. Services for business logic will be provided at run time.
Testing: unit testing and integration testing using Junit framework.
Features of Spring:
- Light Weight
- Inversion Control
- Aspect-Oriented
- Container
- MVC Framework
- Transaction Management
- JDBC Exception Handling
Conclusion:
Spring framework helps the developers to build highly scalable, secure, and robust Java applications faster. Spring framework is still in demand and used by many companies. Moreover, New features are being added to the spring framework.
written by: Laxmi Narayana
reviewed by: Soutik Maity
If you are Interested In Machine Learning You Can Check Machine Learning Internship Program
Also Check Other Technical And Non Technical Internship Programs