Spring Framework Basics - Easy Notes
1. Spring Core Basics
- Spring Framework is a Java-based framework used to build enterprise-level applications.
- It provides support for developing Java applications easily with built-in features like dependency injection
and AOP.
- It is lightweight, modular, and follows POJO (Plain Old Java Object) programming.
- Main features:
- Dependency Injection (DI)
- Inversion of Control (IoC)
- Aspect-Oriented Programming (AOP)
2. Spring Dependency Injection (DI)
- DI means giving an object its dependencies from outside, instead of creating them inside the class.
- It helps in loosely coupled code (easier to test and maintain).
- Spring supports two types of DI:
- Constructor Injection - dependencies are passed via constructor.
- Setter Injection - dependencies are passed via setter methods.
3. Spring Inversion of Control (IoC)
- IoC is a design principle where the control of object creation is given to the framework.
- Instead of a class creating its dependencies, the Spring container creates and injects them.
- Spring uses IoC containers (like BeanFactory and ApplicationContext) to manage objects.
- Helps in building flexible and decoupled applications.
4. AOP (Aspect-Oriented Programming)
- AOP is a programming style used to separate cross-cutting concerns (like logging, security, transactions).
- Instead of writing logging code in every method, AOP allows it to be written separately and applied where
needed.
- Key concepts in AOP:
- Aspect - the common code (e.g., logging).
Spring Framework Basics - Easy Notes
- Join point - a place in code where the aspect is applied (like a method call).
- Advice - the action taken (like before or after a method).
- Pointcut - defines where the advice should apply.