Fixes #24643
Current state
Whether imported user config class will override a scanned one depends on its names.
Unit test which is reproducing it:
ImportTests#importedConfigOverridesScannedOne
During nested configs processing (ConfigurationClassParser#processMemberClasses
), all nested configs are being overridden by its scanned version loosing importedBy
information. This is not intended behavior according to the documentation of import feature. But this accidentally made it work, because otherwise the config would have been registered twice: first by package scan, then by ConfigurationClassBeanDefinitionReader#loadBeanDefinitionsForConfigurationClass
.
Unit test which is reproducing it: ComponentScanAnnotationIntegrationTests#viaContextRegistration_WithComposedAnnotation
Fixed version
Change in ConfigurationClassParser
is needed to make imported configs always override the scanned ones, preserving importedBy
info. Due to preserving importedBy
I had to change ConfigurationClassBeanDefinitionReader
as well, which registers imported configs, but it did not expect that it could have been already registered (during package scanning). I used AnnotationBeanNameGenerator
for naming to make it 100% backward compatible by preserving configs bean names.
Comment From: encircled
@jhoeller just a kind reminder. Lets review&merge or close it. This bug should be addressed somehow though.
Comment From: jhoeller
I have a different implementation strategy in mind as part of a slightly wider revision for 6.2 M1, so I'll close the PR at this point, keeping #24643 open instead. Thanks for the PR in any case! I'm going to make sure to cover the test cases sketched in the PR.