---
title: "Spring in simple terms"
chapter: "01"
---

# Spring in simple terms

Spring manages **objects** and the relationships between them.

## Four words to learn first

| Word | Plain meaning |
|---|---|
| Bean | An object managed by Spring |
| Container | The place that creates and connects beans |
| Dependency | Something one object needs to do its job |
| Injection | Giving an object its dependency from outside |

The main container interface is `ApplicationContext`. It reads configuration,
creates beans, resolves dependencies, applies post-processors, publishes
events, and later closes managed resources.

## A tiny example

```java
@Service
class CheckoutService {
  private final PaymentGateway gateway;

  CheckoutService(PaymentGateway gateway) {
    this.gateway = gateway;
  }
}
```

`CheckoutService` does not create a payment gateway. Spring supplies one.
Constructor injection makes the dependency visible and makes ordinary unit
testing easy.

## Framework versus Boot

Spring Framework provides the programming model: container, AOP, transactions,
web, data access, testing, and integration. Spring Boot chooses compatible
dependencies, auto-configures common infrastructure, embeds a server, and adds
production features. Boot uses Spring; it does not replace it.

## Inversion of Control

Without IoC, application code decides how infrastructure is built. With IoC,
configuration decides how objects are assembled. Business objects focus on
business rules.

## Feynman check

A chef should cook, not build the oven. Dependency injection gives the chef a
working oven. The chef can later receive a test oven without changing recipes.
