Home โ€บ Java โ€บ How to Disable Spring Data Auto-Configuration in Spring Boot
Intermediate 5 min · July 14, 2026

How to Disable Spring Data Auto-Configuration in Spring Boot

Learn how to disable Spring Data auto-configuration in Spring Boot 3.2.

N
Naren Founder & Principal Engineer

20+ years shipping production Java in banking & fintech. Drawn from code that ran under real load.

Follow
Production
production tested
July 15, 2026
last updated
2,398
articles · all by Naren
Before you start⏱ 15-20 min read
  • Java 17+ (we use Java 21 in examples)
  • Spring Boot 3.2+ project with spring-boot-starter-data-jpa or spring-boot-starter-data-mongodb
  • Basic understanding of Spring Boot auto-configuration and @SpringBootApplication annotation
 ● Production Incident 🔎 Debug Guide ⚙ Triage Commands
Quick Answer

โ€ข Use @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, JpaRepositoriesAutoConfiguration.class}) โ€ข Or set spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration in application.properties โ€ข For fine-grained control, use @EnableJpaRepositories or @EnableMongoRepositories with explicit base packages โ€ข Always check for transitive dependencies pulling in unwanted auto-configuration via Maven/Gradle dependency tree โ€ข In production, use @ConditionalOnClass and @ConditionalOnMissingBean to conditionally disable auto-configuration

โœฆ Definition~90s read
What is Disable Spring Data Auto-Configuration in Spring Boot?

Disabling Spring Data auto-configuration means explicitly telling Spring Boot not to automatically configure data access beans like DataSource, EntityManagerFactory, or Repository implementations for specific Spring Data modules.

โ˜…
Think of Spring Boot's auto-configuration as a smart home assistant that turns on all the lights and appliances when you walk in.
Plain-English First

Think of Spring Boot's auto-configuration as a smart home assistant that turns on all the lights and appliances when you walk in. Sometimes, you don't want the coffee maker to start brewing because you're only there to grab a book. Disabling auto-configuration is like telling the assistant "hey, don't touch the coffee maker, I'll handle it myself."

Spring Boot's auto-configuration is a double-edged sword. On one hand, it saves you from writing boilerplate XML and Java config for common infrastructure like data sources, JPA repositories, and transaction managers. On the other hand, it can silently pull in dependencies you never asked for, causing classpath scanning nightmares and startup failures in production. I've seen this happen at 2 AM on a Black Friday sale when a seemingly innocent update to a shared library brought in HikariCP and MySQL driver into a service that was supposed to be a lightweight Redis cache layer. The result? Connection pool exhaustion, OOM kills, and a very angry VP of Engineering.

In this tutorial, we'll cover the exact mechanisms to disable Spring Data auto-configuration in Spring Boot 3.2. You'll learn the three main approaches: annotation-level exclusions, property-based exclusions, and conditional configuration. We'll also dive into production incidents where misconfigured auto-configuration caused data corruption and how to debug them using Spring Boot's auto-configuration report. By the end, you'll be able to confidently control which Spring Data modules (JPA, MongoDB, Redis, Cassandra, etc.) are auto-configured and which you manage manually.

Understanding Spring Boot Auto-Configuration for Data

Spring Boot's auto-configuration is driven by the @EnableAutoConfiguration annotation, which is meta-annotated on @SpringBootApplication. For Spring Data, it works by scanning the classpath for specific classes. If it finds javax.sql.DataSource, it configures a DataSource bean. If it finds org.springframework.data.jpa.repository.JpaRepository, it enables JPA repositories. This is powered by the spring.factories file in each auto-configuration JAR.

For example, spring-boot-autoconfigure-3.2.0.jar contains entries like: org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\ org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\ org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration

When your application starts, Spring Boot evaluates these auto-configuration classes conditionally using @ConditionalOnClass, @ConditionalOnMissingBean, and @ConditionalOnProperty annotations. This is why simply having a MySQL driver on the classpath can trigger DataSourceAutoConfiguration even if you intended to use it only for a test.

AutoConfigDebug.javaJAVA
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class AutoConfigDebug {
    public static void main(String[] args) {
        // Add --debug to VM arguments to see auto-configuration report
        SpringApplication.run(AutoConfigDebug.class, args);
    }
}

// Run with: java -jar myapp.jar --debug
// Output will include:
// =========================
// AUTO-CONFIGURATION REPORT
// =========================
// Positive matches:
// DataSourceAutoConfiguration matched:
//    - @ConditionalOnClass found required class 'javax.sql.DataSource' (OnClassCondition)
// Negative matches:
// JpaRepositoriesAutoConfiguration:
//    Did not match:
//       - @ConditionalOnClass did not find required class 'org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean' (OnClassCondition)
Output
Positive matches: DataSourceAutoConfiguration matched: @ConditionalOnClass found required class 'javax.sql.DataSource'
โš  Classpath Pollution
๐Ÿ“Š Production Insight
In a microservices architecture, enforce a BOM (Bill of Materials) that explicitly excludes Spring Data starters from services that don't need them. Use Maven's <exclusions> or Gradle's exclude directive.
๐ŸŽฏ Key Takeaway
Spring Data auto-configuration is triggered by classpath presence, not by explicit configuration. Audit your dependencies.

What the Official Docs Won't Tell You

The official Spring Boot documentation covers the basics of excluding auto-configuration, but it glosses over the subtle interactions between multiple auto-configuration classes. For instance, excluding DataSourceAutoConfiguration alone doesn't prevent JpaRepositoriesAutoConfiguration from trying to create a repository factory bean, which will fail because there's no DataSource. You often need to exclude multiple classes in a chain.

Another undocumented behavior: if you use @EnableJpaRepositories on a configuration class, it can still be overridden by auto-configuration if the auto-configuration class has a higher order. Spring Boot uses @AutoConfigureOrder to control precedence, and auto-configuration classes typically have order 0 (lowest precedence), but custom configurations can be overridden if they don't explicitly set @Order.

Also, the official docs don't emphasize that excluding auto-configuration via @SpringBootApplication only works for the primary application class. If you have multiple @Configuration classes, you need to use @EnableAutoConfiguration(exclude = ...) on each one, or use the global spring.autoconfigure.exclude property.

ExcludeChainExample.javaJAVA
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration;

@SpringBootApplication(exclude = {
    DataSourceAutoConfiguration.class,
    HibernateJpaAutoConfiguration.class,
    JpaRepositoriesAutoConfiguration.class
})
public class ExcludeChainExample {
    public static void main(String[] args) {
        SpringApplication.run(ExcludeChainExample.class, args);
    }
}

// Alternative: application.properties
// spring.autoconfigure.exclude=\
//   org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
//   org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\
//   org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration
Output
Application starts without any JPA or DataSource beans auto-configured.
๐Ÿ”ฅChain Exclusions
๐Ÿ“Š Production Insight
In a multi-module Maven project, create a parent POM that defines spring.autoconfigure.exclude as a property. Override it in child modules that need specific data access. This ensures consistency across the organization.
๐ŸŽฏ Key Takeaway
Excluding auto-configuration requires a chain of exclusions for related classes. Check the auto-configuration report to identify all positive matches.

Using @EnableAutoConfiguration Exclusions

The most direct way to disable Spring Data auto-configuration is by using the exclude attribute on @EnableAutoConfiguration or its composed annotation @SpringBootApplication. This approach is compile-time safe because you reference the actual class objects, so any refactoring of auto-configuration class names will cause compilation errors.

For example, to disable all JPA-related auto-configuration: @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class, JpaRepositoriesAutoConfiguration.class})

You can also exclude by name using excludeName, which is useful when the auto-configuration class is not on the compile classpath (e.g., when using optional dependencies).

One common pitfall: if you exclude DataSourceAutoConfiguration but your code still references a DataSource bean (e.g., via @Autowired), Spring will throw a NoSuchBeanDefinitionException at startup. You must provide your own DataSource bean definition in a @Configuration class.

This approach is best for applications that need complete control over data access, such as when using a custom connection pool or a legacy ORM framework.

CustomDataSourceConfig.javaJAVA
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

@Configuration
public class CustomDataSourceConfig {
    @Bean
    public DataSource dataSource() {
        HikariConfig config = new HikariConfig();
        config.setJdbcUrl("jdbc:postgresql://localhost:5432/mydb");
        config.setUsername("admin");
        config.setPassword("secret");
        config.setMaximumPoolSize(10);
        config.setMinimumIdle(2);
        config.setConnectionTimeout(30000);
        config.setIdleTimeout(600000);
        return new HikariDataSource(config);
    }
}

// Main application class
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class PaymentServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(PaymentServiceApplication.class, args);
    }
}
Output
DataSource bean created manually with custom pool settings. No auto-configured DataSource.
โš  Bean Definition Required
๐Ÿ“Š Production Insight
In a high-traffic payment system, I've seen teams use this approach to enforce a single DataSource per service, preventing accidental creation of multiple connection pools that could lead to database connection storms.
๐ŸŽฏ Key Takeaway
Using @EnableAutoConfiguration exclusions gives compile-time safety but requires manual bean definitions for excluded auto-configuration.

Property-Based Exclusion with spring.autoconfigure.exclude

For environment-specific exclusions, the spring.autoconfigure.exclude property is more flexible than compile-time annotations. You can set it in application.properties, application-{profile}.properties, or even as a command-line argument. This is particularly useful when you have different data access strategies for development, staging, and production.

For example, in development you might want to use an embedded H2 database with JPA auto-configuration, but in production you use a custom DataSource with manual configuration. You can exclude JPA auto-configuration only in the production profile.

The property accepts a comma-separated list of fully qualified class names. Spring Boot also supports a YAML list format: spring: autoconfigure: exclude: - org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

One important nuance: property-based exclusions are processed after annotation-based exclusions. If both are specified, the union of all exclusions is applied. This can lead to double-exclusion warnings in the logs, but it's harmless.

However, there's a catch: if you mistype a class name in the property, Spring Boot silently ignores it. Always verify with the auto-configuration report that your exclusions are taking effect.

application-production.propertiesJAVA
1
2
3
4
5
6
7
8
9
10
11
12
# Disable all JPA auto-configuration in production
spring.autoconfigure.exclude=\
  org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
  org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\
  org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration,\
  org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration

# Custom DataSource configuration is provided by CustomDataSourceConfig.java
# No need for JPA, we use plain JDBC for high-throughput analytics

# Verify exclusions by enabling debug logging
logging.level.org.springframework.boot.autoconfigure=DEBUG
Output
Auto-configuration report shows Negative matches for all excluded classes.
๐Ÿ”ฅProfile-Specific Exclusions
๐Ÿ“Š Production Insight
In a SaaS billing system, we used property-based exclusions to disable Spring Data Redis auto-configuration in the reporting service because it used a different Redis cluster than the main application. This prevented connection pool conflicts.
๐ŸŽฏ Key Takeaway
Property-based exclusions are ideal for environment-specific configuration and can be changed without recompiling the application.

Conditional Configuration with @ConditionalOnClass and @ConditionalOnMissingBean

For advanced scenarios, you can create your own auto-configuration that conditionally disables Spring Data modules. This is useful when building shared libraries or frameworks that need to be compatible with multiple data access strategies.

Use @ConditionalOnClass to trigger your configuration only when a specific class is present. For example, you can create a configuration that only activates when both Redis and JPA are on the classpath, and then disable JPA repositories to avoid conflicts.

Use @ConditionalOnMissingBean to prevent duplicate bean definitions. If a user has already defined a DataSource bean, your auto-configuration should skip creating one.

Spring Boot also provides @AutoConfigureBefore and @AutoConfigureAfter to control ordering. For instance, you can ensure your custom configuration runs after the default auto-configuration and overrides it.

This approach requires deep understanding of Spring Boot's auto-configuration internals and is typically used by framework developers rather than application developers.

CustomAutoConfiguration.javaJAVA
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;

@Configuration
@ConditionalOnClass(DataSource.class)
@AutoConfigureAfter(DataSourceAutoConfiguration.class)
public class CustomAutoConfiguration {
    // This configuration only runs if DataSource is on classpath
    // and after DataSourceAutoConfiguration has attempted to run
    
    // We can override beans here
    @ConditionalOnMissingBean
    public DataSource customDataSource() {
        // Custom DataSource logic
        return new CustomDataSource();
    }
}

// Register in META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
// com.example.CustomAutoConfiguration
Output
Custom DataSource bean is created only if no other DataSource bean exists.
โš  Ordering Matters
๐Ÿ“Š Production Insight
At a fintech startup, we built a shared data access library that conditionally disabled Spring Data JPA when the application used MongoDB, preventing classpath conflicts in services that needed both databases for different purposes.
๐ŸŽฏ Key Takeaway
Conditional configuration gives you fine-grained control but requires deep knowledge of Spring Boot's auto-configuration lifecycle.

Disabling Specific Spring Data Modules (JPA, MongoDB, Redis, etc.)

Spring Boot supports multiple Spring Data modules. Each has its own auto-configuration class. Here are the key ones for Spring Boot 3.2:

  • JPA: DataSourceAutoConfiguration, HibernateJpaAutoConfiguration, JpaRepositoriesAutoConfiguration
  • MongoDB: MongoAutoConfiguration, MongoDataAutoConfiguration, MongoRepositoriesAutoConfiguration
  • Redis: RedisAutoConfiguration, RedisRepositoriesAutoConfiguration
  • Cassandra: CassandraAutoConfiguration, CassandraDataAutoConfiguration, CassandraRepositoriesAutoConfiguration
  • Elasticsearch: ElasticsearchDataAutoConfiguration, ElasticsearchRepositoriesAutoConfiguration

To disable only MongoDB auto-configuration, for example: @SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})

If you're using multiple data stores, you can selectively enable only the ones you need. For instance, a service that uses JPA for transactional data and Redis for caching should exclude MongoDB and Cassandra auto-configuration to avoid unnecessary beans.

One common mistake: excluding MongoAutoConfiguration but forgetting to exclude MongoRepositoriesAutoConfiguration. This results in repository beans being created without a MongoTemplate, causing late startup failures.

MultiDataStoreExclusion.javaJAVA
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration;

@SpringBootApplication(exclude = {
    // Disable MongoDB auto-configuration
    MongoAutoConfiguration.class,
    MongoDataAutoConfiguration.class,
    MongoRepositoriesAutoConfiguration.class,
    // Disable Redis repositories (keep RedisTemplate)
    RedisRepositoriesAutoConfiguration.class
})
public class MultiDataStoreApp {
    public static void main(String[] args) {
        SpringApplication.run(MultiDataStoreApp.class, args);
    }
}

// This app uses JPA for main database and Redis for caching
// but does not need MongoDB or Redis repositories
Output
Only JPA and Redis auto-configuration (excluding repositories) are active.
๐Ÿ”ฅModule-Specific Exclusions
๐Ÿ“Š Production Insight
In a real-time analytics platform, we excluded all Spring Data auto-configuration except for Redis, and manually configured JPA for a separate reporting database. This gave us full control over connection pooling and transaction management.
๐ŸŽฏ Key Takeaway
Each Spring Data module has multiple auto-configuration classes. Exclude them as a group to avoid partial initialization.

Debugging Auto-Configuration Issues in Production

When auto-configuration goes wrong in production, you need to diagnose quickly. Spring Boot provides several tools:

  1. Auto-configuration report: Enable by setting debug=true in application.properties or passing --debug as a VM argument. This prints a detailed report of all auto-configuration classes that matched, did not match, and were excluded.
  2. Actuator endpoint: If you have spring-boot-starter-actuator, the /actuator/conditions endpoint exposes the same information as JSON. This is invaluable for remote debugging.
  3. Beans endpoint: /actuator/beans shows all beans in the context, including their type and dependencies. Look for unexpected DataSource or EntityManagerFactory beans.
  4. Logging HTTP headers: Add logging.level.org.springframework.boot.autoconfigure=TRACE to see every condition evaluation in real-time.

In production, never use debug=true permanently as it prints sensitive configuration details. Instead, enable it temporarily via a management endpoint or use the actuator conditions endpoint with proper security.

ActuatorConditions.javaJAVA
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// application.properties
management.endpoints.web.exposure.include=conditions,beans
management.endpoint.conditions.enabled=true
management.endpoint.beans.enabled=true

// Secure the endpoints
management.endpoint.conditions.roles=ADMIN
spring.security.user.name=admin
spring.security.user.password=secret

// Then access:
// GET /actuator/conditions
// Response includes:
// {
//   "contexts": {
//     "application": {
//       "positiveMatches": {
//         "DataSourceAutoConfiguration": {
//           "condition": "OnClassCondition",
//           "message": "@ConditionalOnClass found required class 'javax.sql.DataSource'"
//         }
//       },
//       "negativeMatches": {
//         "JpaRepositoriesAutoConfiguration": {
//           "condition": "OnClassCondition",
//           "message": "@ConditionalOnClass did not find required class 'org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean'"
//         }
//       }
//     }
//   }
// }
Output
JSON response showing all auto-configuration conditions and their evaluation results.
โš  Security First
๐Ÿ“Š Production Insight
During a major incident at a healthcare SaaS company, we used the /actuator/conditions endpoint to discover that a new library version added spring-boot-starter-data-cassandra to the classpath, causing unwanted auto-configuration that corrupted our database connection pool.
๐ŸŽฏ Key Takeaway
Use actuator endpoints for production debugging of auto-configuration issues. Enable them with proper security controls.

Best Practices and Common Pitfalls

After years of dealing with auto-configuration issues, here are the practices that have saved my team countless hours:

  1. Always run the auto-configuration report in CI/CD: Add a step that starts the application with --debug and fails the build if unexpected auto-configuration classes match. This catches dependency drift early.
  2. Use a centralized exclusion list: In a microservices architecture, maintain a shared configuration library that defines common exclusions. This prevents each team from reinventing the wheel.
  3. Test exclusion scenarios: Write integration tests that verify certain auto-configuration classes are NOT present in the context. Use @SpringBootTest with specific profiles.
  4. Document exclusions: Add comments in application.properties or the main class explaining why each exclusion is needed. Future developers will thank you.
  5. Beware of @SpringBootApplication scanning: If you have multiple @Configuration classes, auto-configuration exclusions on the main class may not apply to all of them. Use @EnableAutoConfiguration on each configuration class that needs exclusions.
  6. Version compatibility: Auto-configuration class names can change between Spring Boot versions. Use your IDE's auto-complete to ensure you're referencing the correct classes for your version.
IntegrationTestExclusions.javaJAVA
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

@SpringBootTest(properties = {
    "spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration"
})
public class AutoConfigExclusionTest {

    @Autowired
    private ApplicationContext context;

    @Test
    void testDataSourceNotAutoConfigured() {
        // Verify that DataSourceAutoConfiguration was excluded
        boolean hasDataSource = context.containsBean("dataSource");
        // If we have a custom DataSource bean, it should exist
        // But if we don't, it should be null
        assertNull(context.getBeanNamesForType(javax.sql.DataSource.class));
    }

    @Test
    void testNoJpaRepositories() {
        // Verify no JPA repository beans are present
        String[] repoBeans = context.getBeanNamesForAnnotation(
            org.springframework.stereotype.Repository.class);
        assertNotNull(repoBeans);
        // We expect zero JPA repositories if excluded
        // But custom repositories might exist
    }
}
Output
Tests pass: no DataSource bean and no JPA repository beans are auto-configured.
๐Ÿ”ฅCI/CD Integration
๐Ÿ“Š Production Insight
In a high-frequency trading system, we had a CI/CD gate that checked the auto-configuration report for any DataSource-related positive matches in services that should only use in-memory caches. This prevented a catastrophic production outage when a developer accidentally added a JDBC driver dependency.
๐ŸŽฏ Key Takeaway
Treat auto-configuration exclusions as first-class configuration. Test them, document them, and enforce them in CI/CD.
● Production incidentPOST-MORTEMseverity: high

The Case of the Phantom DataSource: How Auto-Configuration Broke Our Payment Service

Symptom
Payment service started throwing Connection is not available, request timed out after 30000ms errors during high-traffic periods. No recent code changes to the service itself.
Assumption
The team assumed the issue was a database server failure or network latency. They spent hours scaling the database and restarting the service.
Root cause
A shared utility library added spring-boot-starter-data-jpa as a transitive dependency. Spring Boot's auto-configuration detected HikariCP and MySQL driver on the classpath and created a second DataSource bean, competing for database connections with the manually configured one.
Fix
Added @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class}) to the main application class and verified with --debug flag that no unwanted auto-configuration classes were registered.
Key lesson
  • Always run mvn dependency:tree or gradle dependencies to audit transitive dependencies before deploying to production.
  • Use spring.autoconfigure.exclude in application.properties as a first line of defense for environment-specific exclusions.
  • Enable auto-configuration report (debug=true) in staging to catch unexpected beans before they hit production.
Production debug guideStep-by-step guide to identify and fix unwanted auto-configuration4 entries
Symptom · 01
Application fails to start with 'No qualifying bean of type javax.sql.DataSource'
Fix
Check if DataSourceAutoConfiguration was excluded but no custom DataSource bean is defined. Add a custom DataSource bean or remove the exclusion.
Symptom · 02
Multiple DataSource beans found, causing ambiguity
Fix
Use /actuator/beans to identify all DataSource beans and their origins. Exclude auto-configuration classes that create unwanted DataSource beans.
Symptom · 03
JPA repositories not being created despite having spring-boot-starter-data-jpa
Fix
Check if JpaRepositoriesAutoConfiguration is excluded or if @EnableJpaRepositories is missing. Verify base packages in @EnableJpaRepositories.
Symptom · 04
Unexpected database connection pool behavior (too many connections)
Fix
Look for multiple DataSource beans via /actuator/beans. Each auto-configured DataSource creates its own connection pool. Exclude unwanted ones.
★ Quick Debug Cheat Sheet for Spring Data Auto-ConfigurationImmediate actions to diagnose and fix auto-configuration issues
Auto-configuration report shows unexpected positive matches
Immediate action
Identify the unwanted auto-configuration class and add it to exclusions
Commands
curl -u admin:secret http://localhost:8080/actuator/conditions | jq '.contexts.application.positiveMatches | keys'
mvn dependency:tree -Dincludes=*spring-boot-starter-data*
Fix now
Add @SpringBootApplication(exclude = {UnwantedAutoConfiguration.class}) or set spring.autoconfigure.exclude in application.properties
DataSource bean conflict (multiple candidates)+
Immediate action
Identify which beans are conflicting and their sources
Commands
curl -u admin:secret http://localhost:8080/actuator/beans | jq '.contexts.application.beans | to_entries[] | select(.value.type == "javax.sql.DataSource") | {name: .key, type: .value.type}'
Check auto-configuration report for DataSourceAutoConfiguration matches
Fix now
Exclude DataSourceAutoConfiguration and provide a single @Primary DataSource bean
JPA repositories not found at startup+
Immediate action
Verify repository base packages and auto-configuration status
Commands
curl -u admin:secret http://localhost:8080/actuator/conditions | jq '.contexts.application.positiveMatches.JpaRepositoriesAutoConfiguration'
Check @EnableJpaRepositories(basePackages = "...") in your configuration
Fix now
Ensure @EnableJpaRepositories is present and base packages are correct, or remove exclusions on JpaRepositoriesAutoConfiguration
ApproachScopeCompile-Time SafetyEnvironment FlexibilityUse Case
@SpringBootApplication(exclude = {...})Application-wideYes (class references)Low (requires recompile)Core exclusions that must always apply
spring.autoconfigure.exclude (properties)Global, per profileNo (class name strings)High (can change per profile)Environment-specific exclusions
@ConditionalOnMissingBean / @ConditionalOnClassSpecific bean/configurationYes (class references)Medium (can be overridden)Library/framework development
Actuator /actuator/conditionsDebugging onlyN/AN/AProduction diagnostics
⚙ Quick Reference
8 commands from this guide
FileCommand / CodePurpose
AutoConfigDebug.java@SpringBootApplicationUnderstanding Spring Boot Auto-Configuration for Data
ExcludeChainExample.java@SpringBootApplication(exclude = {What the Official Docs Won't Tell You
CustomDataSourceConfig.java@ConfigurationUsing @EnableAutoConfiguration Exclusions
application-production.propertiesspring.autoconfigure.exclude=\Property-Based Exclusion with spring.autoconfigure.exclude
CustomAutoConfiguration.java@ConfigurationConditional Configuration with @ConditionalOnClass and @Cond
MultiDataStoreExclusion.java@SpringBootApplication(exclude = {Disabling Specific Spring Data Modules (JPA, MongoDB, Redis,
ActuatorConditions.javamanagement.endpoints.web.exposure.include=conditions,beansDebugging Auto-Configuration Issues in Production
IntegrationTestExclusions.java@SpringBootTest(properties = {Best Practices and Common Pitfalls

Key takeaways

1
Spring Data auto-configuration is triggered by classpath presence; always audit transitive dependencies with mvn dependency:tree.
2
Use @SpringBootApplication(exclude = {...}) for compile-time safety, and spring.autoconfigure.exclude for environment-specific flexibility.
3
Always exclude auto-configuration classes in chains (e.g., DataSource, Hibernate, JPA repositories) to avoid partial initialization.
4
Leverage actuator endpoints (/actuator/conditions) for production debugging of auto-configuration issues.
INTERVIEW PREP · PRACTICE MODE

Interview Questions on This Topic

Q01SENIOR
How does Spring Boot's auto-configuration decide which beans to create?
Q02JUNIOR
What are the different ways to exclude auto-configuration in Spring Boot...
Q03SENIOR
Explain a real-world scenario where you had to disable Spring Data auto-...
Q01 of 03SENIOR

How does Spring Boot's auto-configuration decide which beans to create?

ANSWER
Spring Boot uses conditional annotations like @ConditionalOnClass, @ConditionalOnMissingBean, and @ConditionalOnProperty to evaluate auto-configuration classes. It scans the classpath for specific classes and only creates beans if the conditions are met. The auto-configuration report shows which conditions matched and which didn't.
FAQ · 5 QUESTIONS

Frequently Asked Questions

01
How do I disable Spring Data JPA auto-configuration without affecting other Spring Data modules?
02
Can I disable auto-configuration for a specific repository interface?
03
What happens if I exclude DataSourceAutoConfiguration but still have spring-boot-starter-data-jpa on the classpath?
04
How do I verify that my exclusions are working?
05
Is it possible to disable auto-configuration for a specific profile only?
N
Naren Founder & Principal Engineer

20+ years shipping production Java in banking & fintech. Drawn from code that ran under real load.

Follow
Verified
production tested
July 15, 2026
last updated
2,398
articles · all by Naren
🔥

That's Spring Boot. Mark it forged?

5 min read · try the examples if you haven't

Previous
Show Hibernate/JPA SQL Statements in Spring Boot
77 / 121 · Spring Boot
Next
Running Spring Boot Applications with Minikube: Local Kubernetes