Spring Boot - auto-configuration

Spring Boot auto-configuration makes it easy to configure your application.

Auto-configured

Spring Boot auto-configuration is a feature that automatically configures your Spring application based on the JAR dependencies you have added to your project. It is a way to reduce the amount of boilerplate code you need to write.

You can enable auto configuration by adding @EnableAutoConfiguration to one of your @Configuration classes. Spring Boot will automatically configure your application based on the dependencies you have added to your project.

If you already have @SpringBootApplication, you don’t need to add @EnableAutoConfiguration. @SpringBootApplication already includes @EnableAutoConfiguration.

Disabling Auto-Configuration

If you find configuration class that you don’t want to apply. You can exclude it by adding @EnableAutoConfiguration(exclude = {ClassName.class}) to one of your @Configuration classes.

1
2
3
4
@Configuration
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class MyConfiguration {
}

Debugging Auto-configured

If you want to see what auto-configuration is being applied to your application, you can add --debug to your application start command.
Or you can add debug=true to your application.properties or application.yml file.

application.properties

1
debug=true

When you start your application, you will see CONDITIONS EVALUATION REPORT in the log file. It will show you what auto-configuration is being applied to your application.