public class

AnnotationBeanNameGenerator

extends Object
implements BeanNameGenerator
java.lang.Object
   ↳ org.springframework.context.annotation.AnnotationBeanNameGenerator

Class Overview

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 Java EE 6's javax.annotation.ManagedBean and JSR-330's javax.inject.Named annotations, 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). For example:

com.xyz.FooServiceImpl -> fooServiceImpl

See Also
  • org.springframework.stereotype.Component#value()
  • org.springframework.stereotype.Repository#value()
  • org.springframework.stereotype.Service#value()
  • org.springframework.stereotype.Controller#value()
  • javax.inject.Named#value()

Summary

Public Constructors
AnnotationBeanNameGenerator()
Public Methods
String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry)
Generate a bean name for the given bean definition.
Protected Methods
String buildDefaultBeanName(BeanDefinition definition)
Derive a default bean name from the given bean definition.
String determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotatedDef)
Derive a bean name from one of the annotations on the class.
boolean isStereotypeWithNameValue(String annotationType, Set<String> metaAnnotationTypes, Map<StringObject> attributes)
Check whether the given annotation is a stereotype that is allowed to suggest a component name through its annotation value().
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.beans.factory.support.BeanNameGenerator

Public Constructors

public AnnotationBeanNameGenerator ()

Public Methods

public String generateBeanName (BeanDefinition definition, BeanDefinitionRegistry registry)

Generate a bean name for the given bean definition.

Parameters
definition the bean definition to generate a name for
registry the bean definition registry that the given definition is supposed to be registered with
Returns
  • the generated bean name

Protected Methods

protected String buildDefaultBeanName (BeanDefinition definition)

Derive a default bean name from the given bean definition.

The default implementation simply builds a decapitalized version of the short class name: e.g. "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)

protected 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 null if none is found

protected boolean isStereotypeWithNameValue (String annotationType, Set<String> metaAnnotationTypes, Map<StringObject> attributes)

Check whether the given annotation is a stereotype that is allowed to suggest a component name through its annotation value().

Parameters
annotationType the name of the annotation class to check
metaAnnotationTypes the names of meta-annotations on the given annotation
attributes the map of attributes for the given annotation
Returns
  • whether the annotation qualifies as a stereotype with component name