liveBook · Manning

Component scanning

Also called @ComponentScan

Component scanning is a Spring mechanism that searches configured packages or classpath locations for eligible components and registers them as beans in the application context.

How 2 Manning books explain it

Spring in Action, Sixth Edition

A Spring technique that discovers eligible application components on the classpath and registers them as beans in the application context.

How it is used
Reduces explicit bean configuration by discovering annotated application components.
How deep it goes
Explains how scanning is enabled and discovers an annotated controller, without detailing scan boundaries.
Examples
Uses a Spring Boot bootstrap class and a home-page controller annotated with @Controller.
What you can do after
Apply component scanning with Spring Boot by enabling it through @SpringBootApplication and annotating eligible classes.

Read how Spring in Action, Sixth Edition explains component scanning →

Clean Applications with Hexagonal Architecture

A Spring mechanism that scans specified packages for eligible classes and registers them as application-context beans.

How it is used
Discovers architectural components in the assembly layer and lets Spring wire handlers to implementations of their declared interfaces.
How deep it goes
Configures package scope and annotation filters, distinguishes runtime resolution from declared dependencies, and leaves boundary enforcement to architecture tests.
Examples
Discovers @ApplicationService handlers and @Adapter persistence or notification components under a configured base package.
What you can do after
Configure Spring to discover stereotype-marked beans and resolve implementations for constructor-declared interfaces.

Read how Clean Applications with Hexagonal Architecture explains component scanning →

Also covered in

Related concepts

Questions about component scanning

What is component scanning?

Component scanning is a Spring mechanism that searches configured packages or classpath locations for eligible components and registers them as beans in the application context.

Which Manning books explain component scanning?

Spring in Action, Sixth Edition and Clean Applications with Hexagonal Architecture.

What should I know before learning component scanning?

Manning books that teach component scanning usually introduce Java first.

What is component scanning also called?

Component scanning is also called @ComponentScan.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.