Spring Boot Data starter autoconfiguration behaviour when a configuration is missing, default localhost or error?
06:33 07 Jun 2026

I am currently trying to build a Spring Boot autoconfiguration starter for Apache Solr and trying to decide what is the correct behaviour (convention over user friendliness).

Essentially it seems to be two thought patterns in Spring Data for depedencies.

1. Fail unrecoverable (DataSource / MySQL)

Spring Boot's JDBC autoconfiguration throws at startup when no URL is configured and no embedded database is on the classpath. This could be MySQL, PosgtresSQL, H2 etc.

DataSourceProperties.java (3.4.x)

     private String url;

     public String determineUrl() {
         if (StringUtils.hasText(this.url)) {
             return this.url;
         }
         String databaseName = determineDatabaseName();
         String url = (databaseName != null) ? this.embeddedDatabaseConnection.getUrl(databaseName) : null;
         if (!StringUtils.hasText(url)) {
             throw new DataSourceBeanCreationException(
                 "Failed to determine suitable jdbc url", this, this.embeddedDatabaseConnection);
         }
         return url;
     }

DataSourceAutoConfiguration.java (3.4.x)

The two paths are split via @Conditional:

     // Embedded DB on classpath (H2, HSQLDB, Derby) — auto-configure, no config needed
     @Conditional(EmbeddedDatabaseCondition.class)
     @ConditionalOnMissingBean({ DataSource.class, XADataSource.class })
     @Import(EmbeddedDataSourceConfiguration.class)
     protected static class EmbeddedDatabaseConfiguration {}

     // Pooled DataSource on classpath (HikariCP + external DB) — requires spring.datasource.url
     @Conditional(PooledDataSourceCondition.class)
     @ConditionalOnMissingBean({ DataSource.class, XADataSource.class })
     @Import({ DataSourceConfiguration.Hikari.class, ... })
     protected static class PooledDataSourceConfiguration {}

If you have HikariCP + MySQL driver but no spring.datasource.url, the app refuses to start with a DataSourceBeanCreationException.

2. Silent localhost default (Mongodb, Elasticsearch)

Spring Boot's MongoDB autoconfiguration silently defaults to localhost:27017 when no config is provided.

MongoProperties.java (3.4.x)

     public static final int DEFAULT_PORT = 27017;
     public static final String DEFAULT_URI = "mongodb://localhost/test";

     private String host;   // null — no default
     private String uri;    // null — no default

     public String determineUri() {
         return (this.uri != null) ? this.uri : DEFAULT_URI;
     }

MongoAutoConfiguration.java (3.4.x)

     @Bean
     @ConditionalOnMissingBean
     public MongoClient mongo(ObjectProvider builderCustomizers,
             MongoClientSettings settings) {
         return new MongoClientFactory(builderCustomizers.orderedStream().toList())
                 .createMongoClient(settings);
     }

There is no validation errors or warning, it just starts Spring Boot up and tries to talk to localhost:27017 If there are healthchecks configured then you would get a warning, but otherwise it won't fail until you try to make your first query.

Right approach?

I am wanting to choose the right approach for the library, to me it makes more sense to warn or even stop the service from starting because it is a dependency and why would you want to start a service without it being present.

There are other thoughts though, for instance Solr doesn't have a driver, it just uses HTTP whereas MySQL etc. use JDBC under the hood. So for external data dependencies that don't have a driver, should they just default and not fail during the autoconfiguration phase of a Spring boot service starting?

spring spring-boot spring-data-jpa spring-data spring-data-mongodb