Skip to content

Consider making AutoConfigureAfter|Before annotation value a String array #46669

@ciscoo

Description

@ciscoo

While working on migrating our internal library to be based on the upcoming Spring Boot 4, I encountered issues with the following:

@ConditionalOnClass(ObservationRegistry.class)
@AutoConfiguration
public final class ExampleObservationAutoConfiguration {

    @Configuration(proxyBeanMethods = false)
    @AutoConfigureAfter(WebMvcObservationAutoConfiguration.class)
    @ConditionalOnClass(MeterRegistry.class)
    @ConditionalOnWebApplication(type = Type.SERVLET)
    static final class ExampleMetricsLoggingConfiguration {

    }

}

I understand the modules have moved around, so the import issue related to WebMvcObservationAutoConfiguration not being found is expected. But while looking at the changes for Spring Boot 4, specifically #32883, I can't help but wonder if the contract for @AutoConfigureAfter/@AutoConfigureBefore should be updated to accept a String by default rather than the class.

but users should reference only the names of these classes.

If that is the case, then presuming this means a String rather than Class, then the annotations should become:

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
@Documented
public @interface AutoConfigureAfter {

	String[] value() default {};
}

Dropping references to Class entirely so then this is possible:

@AutoConfigureAfter("com.example.ExampleAutoConfiguation")

instead of:

@AutoConfigureAfter(name = "com.example.ExampleAutoConfiguation")

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions