Spring Boot autoconfiguration configures application components and library integrations from the available environment and configuration. Classpath scanning discovers Spring-annotated classes and adds them to the application context as beans, reducing manual setup. section 1.3 section 1.2
The convenience becomes a constraint when an automatically discovered component is unsuitable, such as a network-calling service that tests must replace with a stub. Using only @SpringBootApplication does not provide enough control; a custom configuration must select relevant autoconfiguration, exclude unwanted configurations, and define the replacement bean. section 1.3
Replacing an automatically discovered bean
A test configuration can use @EnableAutoConfiguration, scan the application package while excluding @SpringBootApplication and WidgetValidator, load test properties, and register a StubWidgetValidator bean. This preserves useful Boot configuration while preventing the real validator from entering the test context. section 1.3
Spring Boot test tooling handles much of this application-context work and can validate that properties, annotations, and configured components cooperate correctly. These tests are slower than unit tests but exercise broader behavior, usually without requiring external services because dependencies can be represented by mocks and stubs. section 1.2
Listing 1.2 A sample configuration for a "test application", without Spring Boot.
@EnableAutoConfiguration
@ComponentScan(basePackageClasses = WidgetApplication.class,
excludeFilters = {
@ComponentScan.Filter(type = FilterType.ANNOTATION, classes = { SpringBootApplication.class }),
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = { WidgetValidator.class }), })
@PropertySource("classpath:test.properties")
static class TestConfiguration {
@Bean
public WidgetValidator testWidgetValidator() {
return new StubWidgetValidator();
}
}
// ... your test code ...
Use the configuration listing to inspect the annotations and bean definition required when automatic discovery must be constrained for testing. section 1.3

