spring-projects / spring-projects/spring-framework

Print out configuration class import tree/order during application startup

Open
#37,156 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: core status: waiting-for-triage
Dominant language
Java
Stars
60.2k
Forks
38.8k
Avg merge
5d 2h
Merged PRs (30d)
27

Description

Feature Description

Currently, users relies on --debug flag to diagnose complex Spring Boot configuration precedence, condition evaluations, and auto-configurations. It can print out positive and negative condition matches (e.g., @ConditionalOnClass, @ConditionalOnMissingBean) for auto-configuration classes. It explains why a configuration evaluated to true or false, but not which parent configuration or @Import chain pulled it into the context.

There is no native way to visualize the actual configuration class import tree (i.e., showing how @Configuration classes, @Import selectors, inner configurations, and auto-configurations trigger one another hierarchically) directly during application startup.

Adding an optional configuration tree logger would make debugging configuration precedence, custom starter ordering, and bean initialization issues significantly easier.

Motivation / Use Case

When building large modular applications or custom Spring Boot starters, developer issues often stem from:

  1. Understanding why a specific auto-configuration or nested configuration was pulled into the context.
  2. Tracking deep chains of @Import / @ImportSelector / @ImportResource annotations.
  3. Verifying processing precedence among user configurations, @AutoConfigureBefore, and @AutoConfigureAfter.

Proposed Implementation

Implementing this feature is straightforward, as a dedicated logger or tree printer can run during the BeanFactoryPostProcessor or ApplicationListener phase to provide instant visual insight into the configuration structure during startup without extra endpoint queries.

Sample code

@Configuration
public class ConfigurationLoggerConfig implements BeanFactoryPostProcessor {
     private static final Logger log = LoggerFactory.getLogger(ConfigurationLoggerConfig.class);

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
        String[] configBeans = beanFactory.getBeanNamesForAnnotation(Configuration.class);
        log.info("=== Registered @Configuration Classes ===");
        for (String name : configBeans) {
            Object configClass = beanFactory.getBeanDefinition(name).getBeanClassName();
            log.info("Config Bean: {} -> {}", name, configClass);
        }
    }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the BeanFactoryPostProcessor and ApplicationListener startup entry points described in the issue, along with the ConfigurationLoggerConfig sample. Clarify how configuration classes, imports, selectors, resources, and ordering should be represented, then define tests or startup output that demonstrate the optional logger reports the complete import tree and order.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.