Skip to content

Improve error message when AutoConfiguration class cannot be found during startup #46559

@0x1227

Description

@0x1227

Problem Description

Spring Boot Version: 2.7.18

When a Spring Boot application fails to start due to missing AutoConfiguration classes, the current error message makes it difficult to identify which Configuration class is causing the issue. This leads to time-consuming debugging sessions where developers have to trace through the entire configuration chain manually.

Current Behavior

When an AutoConfiguration class cannot be found, the application throws an exception like this:

Caused by: java.lang.IllegalArgumentException: Could not find class [org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration]at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:341)
  at org.springframework.core.annotation.TypeMappedAnnotation.adapt(TypeMappedAnnotation.java:474)
  ...
  at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:343)

The stack trace shows that the class org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration cannot be found, but it doesn't indicate which parent Configuration class is trying to import or reference it.

Proposed Enhancement

Enhance the error message in org.springframework.context.annotation.ConfigurationClassPostProcessor#processConfigBeanDefinitions (and related methods in the configuration processing chain) to include information about:

  1. The parent Configuration class that is attempting to import the missing class
  2. The import mechanism being used (e.g., @Import, @AutoConfigurationImportSelector, etc.)
  3. Additional context such as conditional annotations that might be relevant

Expected Improved Error Message

Instead of just:

Could not find class [org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration]

The enhanced error message could be:

Could not find class [org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration]
imported by configuration class [com.example.MyAutoConfiguration] 
via @Import annotation. 
Consider checking if the spring-boot-starter-actuator dependency is included in your classpath.

Benefits

  1. Faster debugging: Developers can immediately identify which configuration is causing the issue
  2. Better developer experience: Clearer error messages reduce frustration and development time
  3. Easier dependency management: Helps identify missing dependencies more quickly
  4. Improved troubleshooting: Support teams can provide better assistance with more context

Potential Implementation Areas

The enhancement would likely involve modifications to:

  • ConfigurationClassPostProcessor.processConfigBeanDefinitions()
  • ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass()
  • Error handling in the configuration import resolution chain

This enhancement would be particularly valuable for developers working with modular applications or custom auto-configurations where the relationship between configuration classes might not be immediately obvious.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: feedback-reminderWe've sent a reminder that we need additional information before we can continuestatus: waiting-for-feedbackWe need additional information before we can continuestatus: waiting-for-triageAn issue we've not yet triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions