Scrivio Interview library
DesignAdvanced6 min read · updated 12 November 2026

You are writing an internal Spring Boot starter for your company's messaging client. How would you use conditions so it works safely across many services?

I would register the starter's configuration as an auto-configuration listed in AutoConfiguration.imports, not through component scanning. Optional integrations go behind @ConditionalOnClass, every bean behind @ConditionalOnMissingBean so services can override it, and the whole feature behind @ConditionalOnProperty with a clear enabled flag and a sensible default. Settings are bound with @ConfigurationProperties and published as configuration metadata, and every supported combination is tested with ApplicationContextRunner.

Why this question is asked

An internal starter is a dependency that many services add to get a feature, here the company's messaging client, configured the company way. Once 50 services depend on it, every decision in it is multiplied: a bean that cannot be replaced blocks a team, an integration that loads without its library breaks startup, and a hidden default surprises someone in production. Interviewers ask this design question to see whether we can use Spring Boot's conditions to make a starter safe and polite. In this answer, we will recap how starters are structured, register the auto-configuration, add classpath, bean and property conditions, bind settings with metadata, and test the combinations.

1A Quick Recap of Starters and Auto-Configuration

A Spring Boot starter is usually two modules. The autoconfigure module contains the configuration classes and their conditions. The starter module is an almost empty jar whose dependencies pull in the autoconfigure module and the libraries the feature needs. Services depend on the starter and get everything.

Auto-configuration classes are ordinary @Configuration classes marked with @AutoConfiguration and listed in a file that Spring Boot reads from every jar. Boot processes them after the application's own configuration, which is what makes conditions such as @ConditionalOnMissingBean reliable.

2Registering as an Auto-Configuration, Not by Scanning

The starter must not rely on component scanning, because the service's packages are not ours, and a starter class found by scanning would be processed as user configuration, too early for its bean conditions. Instead we list the class in the imports file.

Java
# messaging-autoconfigure/src/main/resources/META-INF/spring/
# org.springframework.boot.autoconfigure.AutoConfiguration.imports
com.acme.messaging.autoconfigure.AcmeMessagingAutoConfiguration
@AutoConfiguration
@ConditionalOnClass(AcmeMessagingClient.class)
@ConditionalOnProperty(prefix = "acme.messaging", name = "enabled", havingValue = "true", matchIfMissing = true)
@EnableConfigurationProperties(AcmeMessagingProperties.class)
public class AcmeMessagingAutoConfiguration {
@Bean
@ConditionalOnMissingBean
AcmeMessagingClient acmeMessagingClient(AcmeMessagingProperties props) {
return AcmeMessagingClient.builder()
.brokers(props.brokers())
.timeout(props.timeout())
.build();
}
}

We also keep the auto-configuration in a package the service will not scan, such as com.acme.messaging.autoconfigure, so it is never loaded twice by accident.

3Conditions That Make the Starter Safe

Three kinds of conditions do most of the work. @ConditionalOnClass guards optional integrations: if the client can report metrics through Micrometer, that configuration applies only if Micrometer is on the classpath, so services without it still start. @ConditionalOnMissingBean on every bean lets a service replace any part by defining its own bean of the same type. @ConditionalOnProperty with an enabled flag lets a service turn the feature off, for example in a batch job that shares the codebase but sends no messages.

Java
@AutoConfiguration(after = AcmeMessagingAutoConfiguration.class)
@ConditionalOnClass(MeterRegistry.class) // optional: only with Micrometer
@ConditionalOnBean({AcmeMessagingClient.class, MeterRegistry.class})
class AcmeMessagingMetricsAutoConfiguration {
@Bean
@ConditionalOnMissingBean
AcmeMessagingMetrics acmeMessagingMetrics(AcmeMessagingClient client, MeterRegistry registry) {
return new AcmeMessagingMetrics(client, registry);
}
}
// service without Micrometer: metrics configuration skipped, startup fine
// service with its own AcmeMessagingClient bean: ours backs off, metrics wrap theirs
Which condition answers which question
QuestionCondition
Is the optional library present?@ConditionalOnClass
Has the service defined its own bean?@ConditionalOnMissingBean
Did the service turn the feature off?@ConditionalOnProperty(enabled)
Is there something to attach to?@ConditionalOnBean, with explicit ordering
Is this a web application?@ConditionalOnWebApplication

The default of the enabled flag is a design decision. matchIfMissing = true means adding the starter turns the feature on, which is what most people expect from a starter. For features that connect to production systems or cost money, an explicit opt-in may be safer. Whichever we choose, we document it. Notice the after attribute on the metrics configuration: its @ConditionalOnBean depends on the main configuration having run, so we make that order explicit.

4Binding Settings and Publishing Metadata

All settings live under one prefix and bind to a @ConfigurationProperties record, validated at startup. Adding spring-boot-configuration-processor as an annotation processor generates META-INF/spring-configuration-metadata.json, which gives every service IDE completion and descriptions for acme.messaging.* properties, and a place to mark old properties as deprecated with their replacement.

Java
/**
* Settings for the Acme messaging client.
* @param enabled whether to configure the messaging client
* @param brokers broker addresses, host:port
* @param timeout timeout for sending a message
*/
@ConfigurationProperties("acme.messaging")
@Validated
public record AcmeMessagingProperties(
@DefaultValue("true") boolean enabled,
@NotEmpty List<String> brokers,
@DefaultValue("5s") Duration timeout) { }

5Testing Every Combination With ApplicationContextRunner

A starter's behaviour is the set of beans it produces for each combination of classpath, user beans and properties. ApplicationContextRunner, from Spring Boot's test support, starts a tiny context with chosen auto-configurations in milliseconds, so we can test each combination directly. FilteredClassLoader hides classes to simulate a missing library.

Java
class AcmeMessagingAutoConfigurationTest {
private final ApplicationContextRunner runner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(
AcmeMessagingAutoConfiguration.class, AcmeMessagingMetricsAutoConfiguration.class))
.withPropertyValues("acme.messaging.brokers=localhost:9000");
@Test void createsClientByDefault() {
runner.run(ctx -> assertThat(ctx).hasSingleBean(AcmeMessagingClient.class)); // passes
}
@Test void backsOffWhenServiceDefinesClient() {
runner.withBean(AcmeMessagingClient.class, () -> mock(AcmeMessagingClient.class))
.run(ctx -> assertThat(ctx).hasSingleBean(AcmeMessagingClient.class)); // only theirs
}
@Test void canBeDisabled() {
runner.withPropertyValues("acme.messaging.enabled=false")
.run(ctx -> assertThat(ctx).doesNotHaveBean(AcmeMessagingClient.class));
}
@Test void worksWithoutMicrometer() {
runner.withClassLoader(new FilteredClassLoader(MeterRegistry.class))
.run(ctx -> assertThat(ctx).hasNotFailed().doesNotHaveBean(AcmeMessagingMetrics.class));
}
@Test void failsClearlyWithoutBrokers() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(AcmeMessagingAutoConfiguration.class))
.run(ctx -> assertThat(ctx).hasFailed()); // validation error
}
}

Each test documents one promise the starter makes to services. When someone adds a condition later, a missing test for its combination is easy to spot in review.

6Follow-up questions

Why split the starter into an autoconfigure module and a starter module?

The autoconfigure module can declare optional dependencies for every integration it supports, while the starter chooses which of them a typical service gets. Teams that want a different set can depend on the autoconfigure module directly and add only what they need.

Should a starter define beans without @ConditionalOnMissingBean?

Rarely. Without it, a service that needs a different implementation cannot replace the bean and may end up excluding the whole auto-configuration. The exceptions are internal helper beans that no one should replace, and even then a clearly documented reason helps.

How do you evolve the starter's properties without breaking services?

Add new properties with defaults, and when renaming, keep the old one working for a release while marking it deprecated in the metadata with its replacement, so IDEs warn users. Remove it on a published schedule, with a note in the release notes.

7Conclusion

In this answer, we designed an internal Spring Boot starter for a messaging client. Its configuration is an auto-configuration listed in AutoConfiguration.imports and never component scanned. @ConditionalOnClass guards optional integrations, @ConditionalOnMissingBean lets services override any bean, and @ConditionalOnProperty provides a documented enabled flag. Settings bind to a validated @ConfigurationProperties record with generated metadata, and ApplicationContextRunner tests cover every supported combination of classpath, user beans and properties.

What to say in the interviewAbout 80 seconds aloud

Open with

I would build it as a proper Spring Boot auto-configuration in two modules: an autoconfigure module with the configuration and conditions, and a thin starter that pulls in the dependencies.

Then, if they want more

The configuration class is marked AutoConfiguration and listed in the AutoConfiguration.imports file, in a package services do not scan, because a scanned class would be processed as user configuration and its bean conditions would be evaluated too early. Then the conditions.

ConditionalOnClass guards every optional integration, so the Micrometer metrics part only applies if Micrometer is present and services without it still start. Every bean gets ConditionalOnMissingBean, so a team can replace the client or any helper by defining its own bean. The whole feature sits behind ConditionalOnProperty on acme.messaging.enabled with a documented default, usually on when the starter is added.

If one auto-configuration depends on another's beans, I declare the order with after. Settings bind to a validated ConfigurationProperties record under one prefix, and the configuration processor generates metadata so services get completion, descriptions and deprecation warnings.

Finally, I test each supported combination with ApplicationContextRunner: default beans, back-off with a user bean, disabled by property, missing library simulated with FilteredClassLoader, and a clear failure when required settings are absent.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "You are writing an internal Spring Boot starter for your company's messaging client. How...": https://scrivio-interview-library.netlify.app/spring-boot/spring-configuration/9148f1d701/