Sub topic 8
Seeing what was applied: the conditions report
This chapter assumes you know how @SpringBootApplication triggers auto-configuration and how conditional annotations such as @ConditionalOnClass and @ConditionalOnMissingBean work. It also assumes you can start a Spring Boot application from Maven or Gradle. The earlier chapters explained why Boot makes its decisions. This one shows how to read those decisions after the fact.
Auto-configuration is silent when it works. When it doesn't, you get symptoms: a bean you expected is missing, a default overrode your intent, or a DataSource appears in an application that doesn't use a database. Guessing wastes time. Boot records every condition it evaluates and the outcome, and gives you three ways to read that record.
What the conditions evaluation report is
During startup, Boot evaluates each auto-configuration class and the conditions on its beans. It stores each outcome, matched or not, together with a message that explains it. This record is the conditions evaluation report.
The report answers questions like these:
- Was this auto-configuration class considered at all?
- Which condition decided the result?
- Which of my beans, properties, or classpath entries caused a back-off?
- Did my exclusion take effect?
Turning the report on
The report is logged at DEBUG level, so it does not appear by default. The simplest switch is the debug flag:
java -jar app.jar --debugThe same flag works as a property or a system property:
# application.properties
debug=truejava -Ddebug -jar app.jarWith Maven you can pass it through the plugin:
./mvnw spring-boot:run -Dspring-boot.run.arguments=--debugWith Gradle:
./gradlew bootRun --args='--debug'If you want only the report and not the other debug output, set the logger for the report's package:
logging.level.org.springframework.boot.autoconfigure.logging=DEBUGThis keeps the rest of your logging at its normal level.
When the application fails to start, Boot prints a hint: Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. Re-run with --debug and the report is printed before the failure message. This helps most for startup failures caused by a missing or conflicting bean.
Reading the report
The report has four sections. Each is a heading followed by entries.
| Section | What it lists | Use it to answer |
|---|---|---|
| Positive matches | Auto-configuration classes and beans whose conditions all passed | Why does this bean exist? |
| Negative matches | Classes and beans where a condition failed | Why is this bean missing? |
| Exclusions | Classes removed through `exclude` or `spring.autoconfigure.exclude` | Did my exclusion work? |
| Unconditional classes | Auto-configurations with no conditions | Which classes always apply? |
A trimmed example looks like this:
============================
CONDITIONS EVALUATION REPORT
============================
Positive matches:
-----------------
DataSourceAutoConfiguration matched:
- @ConditionalOnClass found required classes 'javax.sql.DataSource', 'org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType' (OnClassCondition)
DataSourceAutoConfiguration.PooledDataSourceConfiguration matched:
- @ConditionalOnMissingBean (types: javax.sql.DataSource; SearchStrategy: all) did not find any beans (OnBeanCondition)
Negative matches:
-----------------
ActiveMQAutoConfiguration:
Did not match:
- @ConditionalOnClass did not find required class 'jakarta.jms.ConnectionFactory' (OnClassCondition)
Exclusions:
-----------
None
Unconditional classes:
----------------------
org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfigurationEach message has the same shape: the condition annotation, a plain-language outcome, and the condition class in parentheses. The parenthesized name tells you which mechanism made the decision:
OnClassConditionrelates to@ConditionalOnClassand@ConditionalOnMissingClass.OnBeanConditionrelates to@ConditionalOnBeanand@ConditionalOnMissingBean.OnPropertyConditionrelates to@ConditionalOnProperty.OnWebApplicationConditionrelates to@ConditionalOnWebApplication.
Entries can name a whole class (DataSourceAutoConfiguration) or a nested class or @Bean method inside one (DataSourceAutoConfiguration.PooledDataSourceConfiguration). A class can match while one of its beans does not. When a negative match names a nested class, the outer class may still appear under positive matches.
A worked example: the back-off
Suppose the GreetingAutoConfiguration from the previous chapters is on the classpath, and your application also defines its own bean:
package com.example.app;
import com.example.greeting.GreetingService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class AppConfig {
@Bean
public GreetingService greetingService() {
return new GreetingService("Hi");
}
}Run with --debug and search for the auto-configuration:
java -jar app.jar --debug | grep -A4 "GreetingAutoConfiguration"The output will look roughly like this:
Negative matches:
-----------------
GreetingAutoConfiguration#greetingService:
Did not match:
- @ConditionalOnMissingBean (types: com.example.greeting.GreetingService; SearchStrategy: all) found beans of type 'com.example.greeting.GreetingService' greetingService (OnBeanCondition)The class itself matched (its @ConditionalOnClass passed), but the bean method backed off. The message names the type it looked for and the existing bean it found. That is the whole back-off mechanism, shown as a log line.
If GreetingAutoConfiguration appears nowhere in the report, the situation is different. Boot never considered it, which points to a registration problem and not a condition problem.
A diagnosis workflow
Use the report in the same order each time. The diagram shows the decision path.
Step by step:
- Search for the simple class name, for example
GreetingAutoConfigurationorDataSource. - Note the section it appears in.
- Read the message and the condition class in parentheses.
- Change one thing (a dependency, a property, a bean), then re-run and compare.
The "nowhere" branch is the one that surprises people. A class that is absent from every section was never offered to Boot. Common causes are a wrong path or filename for the AutoConfiguration.imports file, a typo in the fully qualified class name inside it, or a dependency jar that is not on the runtime classpath.
Reading the report from a running application
Logs are awkward when the application runs in a container or has already started. The Actuator conditions endpoint exposes the same data as JSON. Add the Actuator starter and expose the endpoint:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>management.endpoints.web.exposure.include=conditionsThen query it:
curl -s http://localhost:8080/actuator/conditionsThe response groups results by application context. Within a context you get positiveMatches, negativeMatches, and unconditionalClasses. Each match entry holds a list of objects with a condition and a message. Negative entries split into notMatched and matched, so you can see which conditions passed before the one that failed. With jq you can answer a specific question:
curl -s http://localhost:8080/actuator/conditions \
| jq '.contexts.application.negativeMatches["com.example.greeting.GreetingAutoConfiguration"]'Reading the report in code
For tests or custom diagnostics you can read the same data from the bean factory. ConditionEvaluationReport holds the outcomes keyed by source name.
package com.example.app;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
@Configuration
public class ConditionsDump {
@Bean
ApplicationRunner printSkipped(ConfigurableListableBeanFactory beanFactory) {
return args -> {
ConditionEvaluationReport report = ConditionEvaluationReport.get(beanFactory);
report.getConditionAndOutcomesBySource().forEach((source, outcomes) -> {
if (!outcomes.isFullMatch()) {
System.out.println("Not applied: " + source);
}
});
};
}
}This prints every source whose conditions did not all pass. It is a debugging aid. Don't leave it in production code.
Common pitfalls
- Searching for the wrong name. The report uses the class's simple name for top-level entries and
Outer.InnerorOuter#methodfor nested ones. Search for a fragment such asGreeting, not the full package. - Mixing up "no match" with "not registered". A class under negative matches was evaluated and rejected. A class that appears nowhere was never evaluated.
- Forgetting that your own beans count.
@ConditionalOnMissingBeansees beans registered by your configuration and by component scanning. A stray@Componentof the matching type can silently disable an auto-configuration. - Reading the report from the wrong context. In applications with a parent context, the Actuator output has one entry per context, each with its own matches. Check the child's
parentIdif a bean seems to come from elsewhere. - Assuming
debug=truechanges behavior. It changes only logging. A problem that disappears with--debugis more likely a timing or ordering issue than something the flag fixed. - Leaving
debug=truein committed configuration. It floods logs with startup detail. Prefer the command-line flag for one-off diagnosis.
Exercise
Your application defines no DataSource bean, yet the conditions report lists DataSourceAutoConfiguration under negative matches with the message "@ConditionalOnClass did not find required class 'javax.sql.DataSource'" ... no wait, you want a database. What does the message tell you to do, and how do you check that the fix worked?
Show answer
The OnClassCondition failure means the required class is not on the runtime classpath, so you need to add a dependency that provides it, such as spring-boot-starter-jdbc or spring-boot-starter-data-jpa plus a database driver. Then re-run with --debug (or query /actuator/conditions) and confirm DataSourceAutoConfiguration now appears under positive matches. If it still appears under negative matches, read the new message: it may now be an OnPropertyCondition or OnBeanCondition failure, such as a missing spring.datasource.url.
Exercise
You added spring.autoconfigure.exclude=com.example.greeting.GreetingAutoConfiguration but a GreetingService bean still exists. Which sections of the report do you check, and what are two likely explanations?
Show answer
Check the Exclusions section first. If the class is listed there, the exclusion worked, and the bean must come from somewhere else, such as a @Bean method or a @Component of your own, which you can find by searching the report for GreetingService. If the class is not listed under Exclusions, the property was not applied. Likely causes are a typo in the fully qualified class name or the property sitting in a file or profile that was not loaded.