liveBook · Manning

@SpringBootApplication

As explained in Testing Spring Boot Applications

@SpringBootApplication is a Spring Boot annotation that identifies an application entry point and enables component scanning and auto-configuration.

@SpringBootApplication marks a Spring Boot application entry point and enables classpath scanning, component discovery, and automatic configuration. Discovered classes become Spring beans in the application context. section 1.3

Use its default behavior carefully when configuring focused test applications:

  • Component scanning may discover dependencies such as external-service implementations that tests should replace. section 1.3
  • Replacing one discovered bean can require custom configuration, selective scanning, auto-configuration, exclusions, properties, and a stub bean. section 1.3
  • A focused test configuration can therefore be preferable when the full application context is inappropriate. section 1.3

Replacing a discovered service

An application that stores Widgets may discover WidgetValidator through @SpringBootApplication. A test that must avoid network calls can exclude that implementation and provide a StubWidgetValidator through custom configuration instead. section 1.3

Figure 1.3 The architecture of the application we would like to test. Arrows represent the data flowing through the system. The WidgetValidator cannot be used in tests, and needs to be replaced by a stub.
ch01 f03 garniermoiroux

Shows the application dependency graph and why an externally accessed validator may need replacement during testing. section 1.3

How Testing Spring Boot Applications covers it

How deep it goes
Explains classpath discovery and bean registration, then stops short of detailing annotation implementation internals.
Examples
Uses a Widget REST application whose discovered external validator must be replaced with a stub.
What you can do after
Operate/configure test applications by recognizing when default component discovery must be replaced with selective configuration.
How it connects
Connects component scanning, auto-configuration, application contexts, Spring beans, test configuration, and stubs.

Also explained in

Compare how 2 books explain @SpringBootApplication →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Testing Spring Boot Applications. The section links point to the parts of the book it draws on.