Scrivio Interview library
LeadershipPrincipal6 min read · updated 12 November 2026

Looking at conditional configuration over many years, where have you seen @Conditional-based designs create long-term risk in large estates, and what rules would you set so that conditional behaviour stays predictable?

The long-term risk comes from many interacting conditions that make a service's behaviour depend on classpath details, which change whenever a transitive dependency changes. The rules I would set are: enable platform features with explicit properties rather than pure classpath detection; make every conditional bean visible in the condition report and documented with its property; test both the enabled and the disabled path of every condition; and remove conditions for features that are no longer used instead of keeping dead branches.

Background to this question

Conditional configuration is what makes Spring Boot pleasant: add a dependency and things work. Over years and hundreds of services, the same mechanism can make behaviour unpredictable, because what a service does is decided by what happens to be on its classpath, and nobody chose that deliberately. A leader is asked this question to see whether they have learned where the convenience turns into risk and can turn that experience into a few rules teams can follow. In this answer, we will look at the patterns that create risk, with an example incident, and then go through each rule with the reasoning behind it.

1How Conditional Designs Turn Into Risk

A condition is a question asked at startup: is this class present, is that bean defined, is this property set. One condition is easy to reason about. The risk grows with interactions: a platform starter with thirty conditional beans, some depending on classes, some on other conditional beans, some on properties, produces a different set of beans for nearly every combination of dependencies. Nobody tests all those combinations, and nobody can predict them by reading code.

Classpath conditions are the most fragile because the classpath is not something teams decide line by line. It is the result of dependency resolution, and a library upgrade can add or remove a transitive dependency without anyone noticing.

2An Example: A Feature Switched On by Accident

Consider a platform auto-configuration that enables distributed caching whenever a Redis client is on the classpath. For years that matched intent: only services that used Redis had the client. Then a reporting library, upgraded in one service for an unrelated reason, began bringing a Redis client as a transitive dependency. On the next deploy, the platform auto-configuration activated, tried to connect to a Redis host that did not exist for that service, and the health check failed in production.

Java
// the risky pattern: behaviour decided by the classpath alone
@AutoConfiguration
@ConditionalOnClass(name = "io.lettuce.core.RedisClient") // true as soon as any library pulls Lettuce in
class PlatformCacheAutoConfiguration { ... }
// mvn dependency:tree after the upgrade:
// +- com.example:reporting-lib:5.2.0
// | \- io.lettuce:lettuce-core:6.x <- new transitive dependency
Step throughHow a transitive change becomes an incident
  1. Library upgraded in one servicefor an unrelated reason
  2. New transitive dependencyRedis client now on the classpath
  3. Classpath condition now trueplatform cache auto-configuration activates
  4. Startup or health check failsno Redis host for this service
  5. Hours to diagnosenobody changed anything related

5 steps in order. Play them, or step through them one at a time.

Nothing in the service's own code or configuration changed. That is the essence of the risk: a change outside the team's attention changes behaviour, and the cause is three steps removed from the symptom.

3Rule 1: Explicit Properties for Platform Features

For the libraries Boot itself integrates, classpath detection is fine and expected. For platform features that change behaviour, such as caching, auditing, outbound security headers or retry policies, the switch should be an explicit property, so the feature is on because someone chose it.

Java
@AutoConfiguration
@ConditionalOnClass(name = "io.lettuce.core.RedisClient") // can it work?
@ConditionalOnBooleanProperty("platform.cache.enabled") // did the team choose it? (Boot 3.5+)
class PlatformCacheAutoConfiguration { ... }

Notice that the class condition stays, but its role changes: it now answers whether the feature can work, while the property answers whether it should. On versions before 3.5, @ConditionalOnProperty with havingValue = "true" does the same.

4Rule 2: Visible and Documented

Every conditional bean from the platform must be explainable without reading source. That means three things. The condition must show up clearly in the condition evaluation report, so custom conditions extend SpringBootCondition and give a message that names what to set. Every enabling property is documented in configuration metadata, so IDEs show it with a description and default. And the platform's documentation lists each feature with its property, its default and what it adds.

A useful practice is to keep Actuator's conditions endpoint available in non-production environments and to save the report at startup in CI, so any change in a service's set of beans appears as a diff in its build.

5Rule 3: Test Both Paths

Each condition has two outcomes, and both are behaviour. The platform tests every conditional configuration with ApplicationContextRunner, once with the condition met and once without, and asserts the beans that should and should not exist.

Java
@Test void cacheOffByDefault() {
runner.run(ctx -> assertThat(ctx).doesNotHaveBean(PlatformCacheManager.class)); // property absent
}
@Test void cacheOnWhenEnabled() {
runner.withPropertyValues("platform.cache.enabled=true")
.run(ctx -> assertThat(ctx).hasSingleBean(PlatformCacheManager.class));
}
@Test void cacheOffWithoutClient() {
runner.withClassLoader(new FilteredClassLoader("io.lettuce")) // simulate absence
.withPropertyValues("platform.cache.enabled=true")
.run(ctx -> assertThat(ctx).doesNotHaveBean(PlatformCacheManager.class));
}

FilteredClassLoader hides classes from the context, which is how we test the absent-library path without building a second project. These tests are cheap, and they turn conditions from assumptions into specified behaviour.

6Rule 4: Remove Conditions for Dead Features

Conditions accumulate. A feature is replaced, its auto-configuration stays behind with a condition that no service meets, and for years it costs nothing visible. Then a dependency change makes the condition true again, and a forgotten configuration activates with outdated defaults. Dead branches are also a tax on every engineer who reads the platform code.

So the platform keeps an inventory of its conditional features with owners, checks in usage data, for example from saved condition reports across services, which branches are never active, and deletes them with a deprecation period. A condition is a commitment to maintain behaviour; if nobody needs the behaviour, the commitment should end.

Rules for predictable conditional behaviour
RulePreventsEnforced by
Explicit property for platform featuresfeatures switched on by the classpathreview checklist, lint on new auto-configs
Visible in report, documented propertyhours of reading sourceSpringBootCondition messages, metadata
Test enabled and disabled pathsuntested combinationsApplicationContextRunner, FilteredClassLoader
Remove dead conditionsforgotten branches reactivatingusage inventory, deprecation cycle

7Follow-up questions

Is classpath detection ever right for platform code?

Yes, as a guard that a feature can work, and for pure integrations that add no behaviour of their own, such as registering metrics for a library when it is present. The line is behaviour: if activation changes what the service does, an explicit property should decide.

How do you catch accidental transitive dependencies before they reach production?

Use dependency convergence and lock files or the Gradle dependency lock, review dependency diffs in pull requests, and compare saved condition reports between builds. A new positive match in the report is a signal worth a look.

How would you introduce these rules into an existing estate?

Apply them to new platform features at once, then convert the riskiest existing classpath-only features, those that have caused incidents, to explicit properties with matchIfMissing = true for a transition release, so behaviour does not change until teams have set the property.

8Conclusion

In this answer, we saw that conditional designs become risky when many interacting conditions let transitive classpath changes alter behaviour, as in the cache that switched on by accident. The rules that keep it predictable are explicit properties for platform features, visibility in the report with documented properties, tests for both paths of every condition, and deleting conditions for features no longer used.

What to say in the interviewAbout 90 seconds aloud

Open with

The risk I've seen most is behaviour that depends on the classpath, which nobody controls line by line. A platform auto-configuration that activates when some client library is present works for years, then a different library upgrade pulls that client in transitively, and a service starts trying to connect to something it never needed.

Then, if they want more

Nothing in the team's code changed, so it takes hours to diagnose. With many interacting conditions, class, bean and property conditions together, the number of combinations is far larger than anyone tests. So I'd set four rules.

First, platform features that change behaviour are enabled by an explicit property, @ConditionalOnBooleanProperty or @ConditionalOnProperty with havingValue true, and the class condition only checks whether the feature can work.

Second, every conditional bean is visible and documented: custom conditions extend SpringBootCondition with clear messages, properties are in configuration metadata, and CI saves the condition report so changes show up as a diff. Third, we test both paths of every condition with ApplicationContextRunner, using FilteredClassLoader to simulate a missing library.

Fourth, we remove conditions for features nobody uses any more, after a deprecation period, because dead branches can reactivate when dependencies change. For existing features I'd migrate the risky ones with matchIfMissing true for a transition release, so nothing changes until teams set the property.

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.
Official documentation
Spring Boot reference
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 "Looking at conditional configuration over many years, where have you seen...": https://scrivio-interview-library.netlify.app/spring-boot/auto-configuration/7b60ad647f/