Skip to content

Inherit enclosing @Conditional on scan-discovered nested configs#36819

Open
Dennis-Mircea wants to merge 1 commit into
spring-projects:mainfrom
Dennis-Mircea:nested-conditional-inheritance
Open

Inherit enclosing @Conditional on scan-discovered nested configs#36819
Dennis-Mircea wants to merge 1 commit into
spring-projects:mainfrom
Dennis-Mircea:nested-conditional-inheritance

Conversation

@Dennis-Mircea
Copy link
Copy Markdown

@Dennis-Mircea Dennis-Mircea commented May 20, 2026

ISSUE link: #36820

Summary

ConfigurationClassParser and ConfigurationClassBeanDefinitionReader already inherit a nested @Configuration class's enclosing-class @Conditional annotations via the importedBy chain, but only when the inner is reached through processMemberClasses or @Import. Inners discovered via @ComponentScan or direct register(...) have no importedBy reference and silently escape the inheritance.

This PR extends both inheritance points to also walk the lexical enclosing chain (via MetadataReaderFactory) when configClass.isImported() is false. @Import semantics are intentionally preserved.

Full context, use case, prior-art relation to Spring Boot #37111, and design rationale are in the linked issue.

Test plan

  • ./gradlew check on the full Spring Framework tree, all green
  • :spring-context:test --tests "*Aot*", :spring-test:test --tests "*Aot*", :spring-beans:test --tests "*Aot*", all green
  • Spring Boot test suite against 7.0.8-SNAPSHOT Framework with this patch published to ~/.m2/repository, all green (~10 min)
  • Seven new tests in EnclosingConditionConfigurationTests pass with the patch and fail (6/7) without it; the 7th is the control case

Signed-off-by: Dennis-Mircea Ciupitu <dennis.mircea.ciupitu@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 20, 2026
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: core Issues in core modules (aop, beans, core, context, expression) status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@Conditional inheritance on nested @Configuration is sensitive to discovery path

3 participants