Spring Boot auto-configuration uses your application’s classpath, environment, and existing beans to decide which configuration classes should contribute bean definitions. It is enabled by @EnableAutoConfiguration, included in @SpringBootApplication; it is conditional rather than a fixed set of defaults, and an application-defined bean can often take the place of a Boot-provided one.
How does Spring Boot opt into auto-configuration?
A typical application starts with @SpringBootApplication. That annotation combines @SpringBootConfiguration, @EnableAutoConfiguration, and @ComponentScan. The first marks the application’s configuration class, the second enables Boot’s auto-configuration, and the third discovers application components. You can use the annotations separately when you need more control over that arrangement. See the Spring Boot annotation reference.
As an Amazon Associate I earn from qualifying purchases.
Auto-configuration is not the same thing as component scanning. Scanning finds application components in packages; auto-configuration considers configuration candidates made available by dependencies.
Where do auto-configuration candidates come from?
Dependencies can publish auto-configuration classes in the resource META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports, with one class name per line. When auto-configuration is enabled, Spring Boot considers the listed candidates. A candidate is not automatically applied just because it is present: its conditions must match. The current auto-configuration authoring guide documents this discovery mechanism.
#1 Best Overall
This is why adding a library can change what an application is capable of configuring, but does not necessarily cause every feature in that library to activate. The library contributes candidates; conditions determine which ones apply in the current application.
How do conditions decide what gets configured?
Conditions test whether an auto-configuration or an individual bean definition is appropriate for the application. A configuration may require a library class to be available, a property to have a particular value, or a particular kind of application context. The guide documents conditions for classes, beans, properties, resources, web-application types, WAR deployment, and SpEL expressions.
Class and bean conditions
@ConditionalOnClass and @ConditionalOnMissingClass check whether classes are present or absent. @ConditionalOnBean and @ConditionalOnMissingBean test the application context. A common pattern is to provide a default bean only when the application has not already supplied a suitable one.
Rank #2
Bean conditions depend on which bean definitions have been processed. For that reason, Spring Boot’s authoring guide recommends applying them to auto-configuration classes, which are loaded after user-defined bean definitions. Optional class references also need care: class-level conditions and conditions on @Bean methods have different class-loading implications. When an optional type might be absent, place references to it in a separately conditioned configuration class.
Property and environment conditions
@ConditionalOnProperty checks environment properties. By default, a present value other than false matches; havingValue and matchIfMissing let configuration specify the expected value and whether an absent property should count as a match. The guide also documents @ConditionalOnBooleanProperty. Check the documentation for your project’s Spring Boot version before using an annotation, since availability can vary by version.
Other condition types
Resource conditions check whether a resource exists. Web conditions distinguish servlet and reactive applications, and deployment conditions can distinguish traditional WAR deployment. Expression conditions evaluate SpEL. Together, these tests let a library offer configuration only in the environments where it is relevant.
Rank #3
What happens when a condition matches?
A matched auto-configuration contributes bean definitions to the application context. That does not mean every corresponding bean instance is created immediately: ordinary bean creation still depends on its dependencies and Spring’s lifecycle.
Recommended Free Tools
Auto-configuration ordering controls when configuration definitions are added, not the later order in which bean instances are created. Ordering metadata is useful when one configuration’s definitions genuinely depend on another’s being processed first; it is not a general way to control runtime initialization.
How can your application replace a Boot default?
Spring Boot describes auto-configuration as “non-invasive.” In practice, many defaults are conditional on the absence of an application-provided bean. For example, the reference guide explains that defining a DataSource causes default embedded-database support to back away. For other defaults, check the relevant configuration and condition rather than assuming every bean is replaceable in the same way. See the auto-configuration reference.
Rank #4
When deciding how to customize behavior, use the narrowest supported control that fits the need:
- Replace one default: define the relevant application bean when the auto-configuration is designed to yield to it.
- Change a setting: use the documented configuration property when the behavior is property-driven.
- Remove a whole configuration: exclude it when the configuration itself should not apply.
Prefer documented properties and public auto-configuration class names. Internal nested configuration classes and bean methods are not stable exclusion targets.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →How do you find out why Spring Boot configured a bean?
Start the application with --debug to produce a conditions report. Inspect both positive and negative outcomes to see which configurations matched and which conditions did not. This is more useful than guessing from a bean’s name: it shows whether the relevant class, property, bean, or application type satisfied a condition.
- Run the application with the
--debugcommand-line argument. - Find the conditions report in the startup output.
- Locate the relevant auto-configuration and inspect its positive and negative matches.
- Use the matching condition to choose a property or user bean customization; exclude the configuration only if it should not apply at all.
How do you exclude an auto-configuration?
Spring Boot supports exclusions through annotation attributes or the spring.autoconfigure.exclude property. Use the public auto-configuration class name, and confirm that it exists in the Spring Boot version used by the project.
An exclusion is broader than replacing a single default bean: it removes the named auto-configuration from consideration. Diagnose the condition report first, and use a bean or property customization instead when that is the intended extension point. The auto-configuration reference documents both exclusion approaches and cautions against relying on internal nested classes or bean methods.
How should library authors provide auto-configuration?
For a reusable library, publish auto-configuration classes through META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports rather than relying on component scanning to find them. The auto-configuration classes should not be discovered through component scanning and should not enable component scanning themselves; use explicit @Import for additional configuration where needed.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsApply conditions at the configuration-class or bean-method level, and use ordering only when there is a real dependency between bean definitions. Test combinations of classpath contents, environment properties, and user-defined beans in controlled contexts with ApplicationContextRunner. The authoring guide covers these practices.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




