Sitemap

Member-only story

How to Disable Auto-Configuration in Spring Boot (Step-by-Step Guide)

Learn how to disable specific auto-configurations in Spring Boot using the exclude attribute and @EnableAutoConfiguration. Includes real-world examples and best practices.

2 min readMar 25, 2025

--

🔍 What Is Auto-Configuration in Spring Boot?

Spring Boot’s auto-configuration feature automatically configures your application based on the dependencies in your classpath.

✅ It reduces boilerplate code.

❌ But sometimes, it can load configurations you don’t want.

For example:

  • You may not want to use a database, but Spring Boot configures a DataSource by default.
  • You may want to override the default configuration manually.

In such cases, you can disable specific auto-configurations.

🔧 3 Ways to Disable a Specific Auto-Configuration

✅ 1. Use exclude in @SpringBootApplication

This is the most common and recommended way to disable unwanted auto-configuration classes.

@SpringBootApplication(
exclude = {
DataSourceAutoConfiguration.class,
HibernateJpaAutoConfiguration.class
}
)
public class MyApp {
public static void…

--

--

No responses yet