Yes, Spring Boot allows developers to customize or override specific auto-configurations. While Spring Boot automatically configures components based on dependencies and application settings, it also provides several ways to modify this behavior to meet application-specific requirements.
What is Auto-Configuration?
spring-boot-starter-data-jpa
and a database driver,
without requiring manual configuration.
How Can We Customize Auto-Configuration?
1. Using application.properties or application.yml
Many auto-configured settings can be overridden through configuration files.
spring.datasource.url=jdbc:mysql://localhost:3306/testdb
spring.datasource.username=root
spring.datasource.password=adminSpring Boot uses these values instead of its defaults.
2. Defining a Custom Bean
If we define our own bean, Spring Boot usually backs off and uses our implementation.
@Configuration
public class AppConfig {
@Bean
public DataSource dataSource() {
return new HikariDataSource();
}
}Here, Spring Boot uses the custom DataSource bean instead of creating one automatically.
3. Excluding Auto-Configuration
Sometimes an auto-configuration is not needed.
@SpringBootApplication(
exclude = {
DataSourceAutoConfiguration.class
}
)
public class Application {
}This prevents Spring Boot from configuring a DataSource.
4. Using @Conditional Annotations
Custom configurations can be loaded only when certain conditions are met.
@Configuration
@ConditionalOnProperty(
name = "feature.enabled",
havingValue = "true")
public class FeatureConfig {
}feature.enabled=true
5. Using @Primary
When multiple beans of the same type exist, one can be marked as the preferred bean.
@Bean
@Primary
public DataSource customDataSource() {
return new HikariDataSource();
}Spring will inject this bean by default.
Suppose Spring Boot automatically configures a DataSource for MySQL.
Use a custom connection pool configuration.
This allows customization without disabling the entire auto-configuration mechanism.
Common Auto-Configurations That Are Customized
Benefits of Customizing Auto-Configuration
Real-World Example
HikariCP DataSource
This keeps the benefits of auto-configuration while allowing fine-grained customization.
A concise interview answer is
Yes, Spring Boot auto-configuration can be customized in several ways. We can override default settings using application.properties or application.yml, define our own beans to replace auto-configured beans, exclude specific auto-configurations using the exclude attribute, or use conditional annotations for custom behavior. This flexibility allows us to leverage Spring Boot's automation while still meeting application-specific requirements.
Last updated: 11 November 2026
Previous question: Why is auto-configuration important in a Spring Boot application?
Next question: How do starters simplify the Maven or Gradle configuration?