Lesson 1 · Spring Core

The IoC Container

Beans, dependency injection, and the ApplicationContext — the one idea the whole framework is built on.

Why this is Lesson 1 Every other topic — AOP, transactions, MVC, Boot auto-config — is beans being created and wired by the container. Nail this and the rest of the exam is detail. Expect ~8–12 core questions to lean on it.

The problem Spring solves

Without a framework, objects create their own collaborators:

class TransferService {
  // tightly coupled: TransferService decides the exact implementation
  private AccountRepository repo = new JdbcAccountRepository();
}

Now TransferService can never use a different repository, and you can't unit-test it with a fake. It controls its own dependencies. Inversion of Control (IoC) flips that: the framework decides what to create and hands dependencies in.

class TransferService {
  private final AccountRepository repo;
  // the dependency is injected from outside — constructor injection
  TransferService(AccountRepository repo) { this.repo = repo; }
}
IoC vs DI Inversion of Control is the principle (the framework is in charge of object creation). Dependency Injection is the technique Spring uses to implement it (supplying dependencies from outside). DI is a kind of IoC.

Beans and the container

A bean is simply an object that the Spring IoC container instantiates, assembles, and manages. You describe what beans exist and how they depend on each other (via annotations, Java @Configuration, or XML); the container reads that metadata and builds the fully-wired object graph for you.

TermWhat it is
BeanAn object created & managed by the container. If Spring made it, it's a bean.
ContainerThe thing that reads config metadata and produces the wired beans.
Configuration metadataHow you tell the container what to build: annotations, @Bean methods, or XML.

BeanFactory vs ApplicationContext

There are two container interfaces. You will use ApplicationContext — but the exam tests that you know how they differ.

BeanFactoryApplicationContext
RoleMost basic containerSuperset — extends BeanFactory
Singleton creationLazy (on first request)Eager at startup
ExtrasJust DIEvents, i18n (MessageSource), resource loading, auto-registers post-processors
Exam trap ApplicationContext eagerly pre-instantiates singleton beans when the context starts, so misconfiguration blows up immediately at startup — not later at first use. A plain BeanFactory is lazy. This "eager vs lazy" line is a classic question.

Common ApplicationContext implementations

// From @Configuration / @Component classes (the modern default)
ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);

// From XML on the classpath
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");

TransferService svc = ctx.getBean(TransferService.class);

Note: DefaultListableBeanFactory is a BeanFactory, not an ApplicationContext — a favourite distractor in "which of these is an ApplicationContext?" questions.

The three ways to inject

Remember for the exam Constructor injection is the recommended default. Since Spring 4.3, if a class has a single constructor you don't even need @Autowired on it — Spring uses it automatically.
Primary source — read this
Spring Framework 5.3 — Core Technologies: The IoC Container

Sections 1.1–1.4. Read the intro, "Container Overview", and "Dependencies". 20 minutes, and it maps 1-to-1 onto this lesson.

Check yourself

Exam-shaped questions. Answer before revealing — retrieval is what makes it stick.

Now drill — 20 questions, instant feedback Do the full Container Drill (Q1–20) → right here on the site. It covers the same concepts as the Container section of your book, in fresh wording. Flag anything you miss and bring it to me. Then keep your book open for Q21–40 as a second pass.
Bonus skill Want to lock this in even harder? Learn to write your own exam questions → — the single best way to turn "I recognise it" into "I understand it".
I'm your teacher — ask me anything. Confused about eager vs lazy, or why constructor injection wins? Ask in the chat. When you're ready, say "continue" and I'll build Lesson 2 (Java Configuration) and push it live.
← Dashboard Lesson 2 · Java Configuration → (coming next)