You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow usage of BeanNameGenerator in ImportBeanDefinitionRegistrars #22591
A BeanNameGenerator can be configured for usage in component scanning configuration classes. That support allows custom annotation based activation of functionality via annotations importing an ImportBeanDefinitionRegistrar. Its primary callback method unfortunately currently doesn't provide access to the BeanNameGenerator potentially provided so that a customization of that generator cannot be considered for components registered via the registrar.
It would be nice, if there was a way to consume the BeanNameGenerator to allow components being registered to follow the configured naming strategy.
changed the title [-]Allow usage of BeanNamGenerator in ImportBeanDefinitionRegistars[/-][+]Allow usage of BeanNameGenerator in ImportBeanDefinitionRegistrars[/+]on Mar 14, 2019
It looks like we're getting the generator that's used for the configuration class scanning, not the one used to name scanned components. I've put in check for the enclosing class of the provided instance to only opt in using it if it's not ConfigurationClassPostProcessor. Is there maybe a chance we can expose the default one used in a slightly more convenient way (a constant in ConfigurationClassPostProcessor maybe)?
@odrotbohm So you'd simply like to be able to ignore the default import bean name generator more easily, e.g. by comparing it to a constant on ConfigurationClassPostProcessor, proceeding with an externally configured BeanNameGenerator only?
Yes. Fundamentally, we're scanning for components ourselves. I.e. for us, the bean name generator used to name scanned components would be the more appropriate one. It looks like the user override is trumping both default variants Spring Framework uses internally.
If that stays the same, I'm fine with just using the one handed down, if it's not the default one. To detect that, something to easily compare the handed down instance to would allow us to remove the rather brittle check of inspecting the surrounding class.
Alright, I've added an IMPORT_BEAN_NAME_GENERATOR constant on ConfigurationClassPostProcessor, along with a common AnnotationBeanNameGenerator.INSTANCE that serves as the default for component scanning purposes.
I hate to bring this up again but we face the same issue with the XML flavor as the BeanDefinitionReader exposes an instance of DefaultBeanNameGenerator. If that in use, we have to fall back to an AnnotationBeanNameGenerator. I fall back to our default value if the handed in instance is a exactly DefaultBeanNameGenerator assuming that all customizations would have to either provide a subtype or a completely different implementation of BeanNameGenerator.
However, ultimately we're facing the same slightly brittle situation of detecting the default.
Hmm, in line with the common instance constants, DefaultBeanNameGenerator should have one too... So if we introduce an INSTANCE constant there as well, used for defaulting like we do for AnnotationBeanNameGenerator already, would that be sufficient for your purposes?
Activity
[-]Allow usage of BeanNamGenerator in ImportBeanDefinitionRegistars[/-][+]Allow usage of BeanNameGenerator in ImportBeanDefinitionRegistrars[/+]DATACMNS-1497 - Configuration infrastructure now considers scanning B…
DATACMNS-1497 - Configuration infrastructure now considers scanning B…
odrotbohm commentedon Mar 15, 2019
It looks like we're getting the generator that's used for the configuration class scanning, not the one used to name scanned components. I've put in check for the enclosing class of the provided instance to only opt in using it if it's not
ConfigurationClassPostProcessor. Is there maybe a chance we can expose the default one used in a slightly more convenient way (a constant inConfigurationClassPostProcessormaybe)?sbrannen commentedon Mar 17, 2019
Reopening to consider comments from @odrotbohm.
jhoeller commentedon Apr 2, 2019
@odrotbohm So you'd simply like to be able to ignore the default import bean name generator more easily, e.g. by comparing it to a constant on
ConfigurationClassPostProcessor, proceeding with an externally configuredBeanNameGeneratoronly?odrotbohm commentedon Apr 2, 2019
Yes. Fundamentally, we're scanning for components ourselves. I.e. for us, the bean name generator used to name scanned components would be the more appropriate one. It looks like the user override is trumping both default variants Spring Framework uses internally.
If that stays the same, I'm fine with just using the one handed down, if it's not the default one. To detect that, something to easily compare the handed down instance to would allow us to remove the rather brittle check of inspecting the surrounding class.
jhoeller commentedon Apr 2, 2019
Alright, I've added an
IMPORT_BEAN_NAME_GENERATORconstant onConfigurationClassPostProcessor, along with a commonAnnotationBeanNameGenerator.INSTANCEthat serves as the default for component scanning purposes.DATACMNS-1497 - Configuration infrastructure now considers scanning B…
odrotbohm commentedon Apr 3, 2019
I hate to bring this up again but we face the same issue with the XML flavor as the
BeanDefinitionReaderexposes an instance ofDefaultBeanNameGenerator. If that in use, we have to fall back to anAnnotationBeanNameGenerator. I fall back to our default value if the handed in instance is a exactlyDefaultBeanNameGeneratorassuming that all customizations would have to either provide a subtype or a completely different implementation ofBeanNameGenerator.However, ultimately we're facing the same slightly brittle situation of detecting the default.
DATACMNS-1497 - Polishing.
jhoeller commentedon Apr 3, 2019
Hmm, in line with the common instance constants,
DefaultBeanNameGeneratorshould have one too... So if we introduce anINSTANCEconstant there as well, used for defaulting like we do forAnnotationBeanNameGeneratoralready, would that be sufficient for your purposes?odrotbohm commentedon Apr 3, 2019
Yes, I think so.
Allow usage of BeanNameGenerator in ImportBeanDefinitionRegistrars
Common constants for default AnnotationBeanNameGenerator instances
Common constant for DefaultBeanNameGenerator as well