Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce BeanNameGenerator based on fully qualified class name
Prior to this commit, Spring offered two top-level implementations of the BeanNameGenerator strategy: DefaultBeanNameGenerator and AnnotationBeanNameGenerator. The latter is used as the default bean name generator for beans picked up via component scanning. In a typical application, this strategy works well; however, if multiple component scanned beans have the same simple class name (i.e., identical names ignoring the package), a BeanDefinitionStoreException is thrown. To address such naming conflicts, users of Spring have had to implement a custom BeanNameGenerator based on the fully qualified class name of such components. Similar conflicts can arise with components registered via configuration class imports (i.e., via @import), and ConfigurationClassPostProcessor addresses this via an anonymous inner class that extends AnnotationBeanNameGenerator but falls back to using the fully qualified class name if an explicit bean name is not provided via an annotation. This commit extracts the implementation of ConfigurationClassPostProcessor's internal BeanNameGenerator into a new top-level FullyQualifiedAnnotationBeanNameGenerator class that can be used to disambiguate between same-named components residing in different packages that are picked up via component scanning. This bean name generator can be configured via @componentscan's nameGenerator attribute. Closes gh-24114
- Loading branch information