liveBook · Manning

Component scanning

As explained in Clean Applications with Hexagonal Architecture

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

Listing every bean in a composition root is avoidable: component scanning discovers eligible classes and registers them with Spring. In a hexagonal design, the assembly layer configures discovery while the application core remains independent of Spring. section 6.2.2 section 9.6.2

The assembly module can scan a base package and add annotation filters for architectural stereotypes such as @ApplicationService, @Adapter, and @DomainService. Scanning discovers candidates and resolves implementations; constructor dependencies remain explicitly declared. It does not enforce framework boundaries—architecture tests do that. section 6.2.2 section 9.6.2

Listing 6.4 ApplicationAssembler with annotation-based component scanning
@Configuration
@ComponentScan(
  basePackages = "com.writeflow",
  includeFilters = @ComponentScan.Filter( #A
    type = FilterType.ANNOTATION,
    classes = {
      ApplicationService.class, #B
      Adapter.class,
      DomainService.class
    }
  )
)
class ApplicationAssembler {
}

Shows an assembly configuration that scans a package and registers classes marked with architectural annotations. section 6.2.2

How Clean Applications with Hexagonal Architecture covers it

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 it assumes
Assumes architectural stereotypes are defined in the kernel and Spring configuration belongs to the assembly module.
What you can do after
Configure Spring to discover stereotype-marked beans and resolve implementations for constructor-declared interfaces.
How it connects
Connects dependency injection, composition roots, architectural stereotypes, and hexagonal architecture.

Also explained in

Compare how 2 books explain component scanning →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clean Applications with Hexagonal Architecture. The section links point to the parts of the book it draws on.