Spring Framework
Framework:-
- Frameworks are the ultimate time-savers for anyone looking to perform tasks efficiently. By utilizing pre-built software solutions, frameworks eliminate the need for tedious coding and enable you to focus on business logic more.
- With the help of a framework developing becomes easy. e.g. Spring, Hibernate, etc.
- It reduces the complexity of an object.
Spring Framework:-
- Spring is a Java-based application that is used to develop enterprise(e-commerce) applications. e.g. Amazon, Flipkart, Naptol, etc.
- Spring is also a dependency injection framework.
- Spring is a helpful tool for developing loosely coupled applications. With Spring, you can easily build applications that are not tightly bound.
Important Definitions in Spring Framework
Inversion of control (IOC):-
- It is the process of transferring control of an object to the spring framework is called inversion of control.
- In other words, IOC is a process wherein the control of an object (creating and injecting the object) is transferred to the spring framework.
- IOC is achieved with the help of dependency injection.
Dependency Injection:-
- Dependency Injection is a design pattern that is used to achieve inversion of control(IOC).
- It is used to inject or insert one object into another object.
- There are two types of dependency injection.
- Property Injection.
- Constructor Injection.
Design pattern:-
- A design pattern is a solution to a problem that occurs repeatedly in a project.
- A design pattern is a typical solution or general solution to all the commonly occurring problems.
- Example:- Singleton Design pattern and Dependency Injection.
Spring Container or Spring IOC Container:-
- A spring container is a component that is responsible for creating an object, storing an object in the memory and injecting the object whenever it is necessary.
- In simple words, Spring Container is responsible for the lifecycle of an object.
- <<ApplicationContext>> is a predefined interface that manages the lifecycle of an object.
Note:-
- We consider Application Context as our Spring Container.
Implementation classes of ApplicationContext:-
- ClassPathApplicationContext
- FileSystemXmlApplicationContext
- WebXmlApplicationContext
- AnnotationConfigApplicationContext
Note:-
- For the Spring Container, we need to provide the information regarding bean class and configuration.
Mandatory rules for creating Java Bean class:-
- public non-abstract class
- private data members
- public getter and setter method.
Steps to achieve dependency injection (setter or property injection):-
- Create a Java project with the respective package.
- Download the Spring Jar files and add them to the build path.
- Create a Bean Class with respect to the getter and setter method.
- Create a configuration file (XML file).
- Search for the configuration file get the bean and utilize the bean.