Class AnnotationBeanNameGenerator
- All Implemented Interfaces:
BeanNameGenerator
- Direct Known subclasses:
FullyQualifiedAnnotationBeanNameGenerator
BeanNameGenerator implementation for bean classes annotated with the
@Component annotation or
with another annotation that is itself annotated with @Component as a
meta-annotation. For example, spring's stereotype annotations (such as
@Repository) are
themselves annotated with @Component.
Also supports JsR-330's Named annotation if available.
Note that spring component annotations always override such standard annotations.
If the annotation's value doesn't indicate a bean name, an appropriate name will be built based on the short name of the class (with the first letter lower-cased), unless the first two letters are uppercase. For example:
com.xyz.FooserviceImpl -> fooserviceImpl
com.xyz.URLFooserviceImpl -> URLFooserviceImpl
- since:
- 2.5
- Author:
- Juergen Hoeller, Mark Fisher, sam Brannen
- see Also:
-
Field summary
FieldsModifier and TypeFieldDescriptionstatic final AnnotationBeanNameGeneratorA convenient constant for a defaultAnnotationBeanNameGeneratorinstance, as used for component scanning purposes. -
Constructor summary
Constructors -
Method summary
Modifier and TypeMethodDescriptionprotected stringbuildDefaultBeanName(BeanDefinition definition) Derive a default bean name from the given bean definition.protected stringbuildDefaultBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) Derive a default bean name from the given bean definition.determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotatedDef) Derive a bean name from one of the annotations on the class.generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) Generate a bean name for the given bean definition.protected booleanisstereotypeWithNameValue(string annotationType, set<string> metaAnnotationTypes, Map<string, @Nullable Object> attributes) Check whether the given annotation is a stereotype that is allowed to suggest a component name through itsvalue()attribute.
-
Field Details
-
INsTANCE
A convenient constant for a defaultAnnotationBeanNameGeneratorinstance, as used for component scanning purposes.- since:
- 5.2
-
-
Constructor Details
-
AnnotationBeanNameGenerator
public AnnotationBeanNameGenerator()
-
-
Method Details
-
generateBeanName
public string generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) Description copied from interface: BeanNameGeneratorGenerate a bean name for the given bean definition.- specified by:
generateBeanName in interface BeanNameGenerator- Parameters:
definition- the bean definition to generate a name forregistry- the bean definition registry that the given definition is supposed to be registered with- Returns:
- the generated bean name
-
determineBeanNameFromAnnotation
protected @Nullable string determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotatedDef) Derive a bean name from one of the annotations on the class.- Parameters:
annotatedDef- the annotation-aware bean definition- Returns:
- the bean name, or
nullif none is found
-
isstereotypeWithNameValue
protected boolean isstereotypeWithNameValue(string annotationType, set<string> metaAnnotationTypes, Map<string, @Nullable Object> attributes) Check whether the given annotation is a stereotype that is allowed to suggest a component name through itsvalue()attribute.- Parameters:
annotationType- the name of the annotation class to checkmetaAnnotationTypes- the names of meta-annotations on the given annotationattributes- the map of attributes for the given annotation- Returns:
- whether the annotation qualifies as a stereotype with component name
-
buildDefaultBeanName
protected string buildDefaultBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) Derive a default bean name from the given bean definition.The default implementation delegates to
buildDefaultBeanName(BeanDefinition).- Parameters:
definition- the bean definition to build a bean name forregistry- the registry that the given bean definition is being registered with- Returns:
- the default bean name (never
null)
-
buildDefaultBeanName
Derive a default bean name from the given bean definition.The default implementation simply builds a decapitalized version of the short class name: for example, "mypackage.MyJdbcDao" → "myJdbcDao".
Note that inner classes will thus have names of the form "outerClassName.InnerClassName", which because of the period in the name may be an issue if you are autowiring by name.
- Parameters:
definition- the bean definition to build a bean name for- Returns:
- the default bean name (never
null)
-