What is Spring?
A Brief History
The Spring Framework was created by Rod Johnson and released in 2003 as an open source Java platform. The framework grew out of his book Expert One-on-One J2EE Design and Development, which heavily criticized the cumbersome and slow heavyweight EJB 2.x patterns.
The main goal of Spring: simplify Java application development without having to rely on overly complex components.
Core Concept: IoC Container
Spring is built on the concept of Inversion of Control (IoC). Instead of objects creating their own dependencies, the Spring container prepares and manages those objects.
// Without IoC — the class creates its own dependencies
public class OrderService {
private PaymentService payment = new PaymentService(); // tight coupling
}
// With IoC — the container injects the dependencies
public class OrderService {
private final PaymentService payment;
public OrderService(PaymentService payment) {
this.payment = payment; // loose coupling
}
}
AOP (Aspect-Oriented Programming)
Spring supports AOP to separate cross-cutting concerns such as logging, security, and transaction management from the main business logic.
| AOP Concept | Description |
|---|---|
| Aspect | Logging, security, and other modules |
| Join Point | Point of execution (method call, exception) |
| Advice | Action executed at a join point |
| Pointcut | Expression that determines which join point |
Why Is Spring Popular?
- POJO-based: No need to extend special framework classes
- Modular: Take only the modules you need
- Testable: Unit testing is easy thanks to loose coupling
- Mature: Trusted by thousands of enterprise companies since 2003
Spring Ecosystem
Spring Framework (core)
├── Spring Boot → Auto-config, embedded server
├── Spring Data → Database access (JPA, MongoDB, Redis)
├── Spring Security → Authentication & authorization
├── Spring Cloud → Microservices (config, discovery, gateway)
├── Spring Batch → Batch processing
├── Spring WebFlux → Reactive programming
└── Spring Integration → Enterprise integration patterns
Summary
| Feature | Description |
|---|---|
| IoC Container | Manages object lifecycle and dependencies |
| AOP | Separates cross-cutting concerns |
| Modular | Take modules as needed |
| POJO-based | Does not depend on framework classes |
| Open source | Free, large community, complete documentation |
The Spring Framework is the foundation of almost every modern Java application in the enterprise. However, configuring pure Spring manually can be very cumbersome. In the next chapter, we'll get to know Spring Boot, which makes the entire setup process much easier.