Core Spring Framework ideas — dependency injection, inversion of control, and building loosely coupled components.
Question 1: What is Spring Framework?
Ans
Spring is a Java framework that provides infrastructure for building applications, especially backend and enterprise systems. Core Spring concepts include dependency injection, inversion of control, web support, transactions, and integration with data technologies.
It reduces boilerplate and encourages loosely coupled components.
Example
java
@Service
class UserService {
private final UserRepository repo;
UserService(UserRepository repo) { this.repo = repo; }
}
Important Point
Spring Framework is broader than Spring Boot; Boot builds on Spring and simplifies application setup.
Question 2: What is dependency injection?
Ans
Dependency injection means an object receives the dependencies it needs from outside instead of constructing them itself.
This improves testability and reduces tight coupling between classes.
Example
java
@Service
class OrderService {
private final PaymentService paymentService;
OrderService(PaymentService paymentService) {
this.paymentService = paymentService;
}
}
Important Point
Constructor injection is generally preferred because dependencies are explicit and can be final.