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 Jakarta EE's jakarta. and
JSR-330's jakarta. annotations (as well as their pre-Jakarta
javax.annotation.ManagedBean and javax.inject.Named equivalents),
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
org.springframework.stereotype.Component#value() , org.springframework.stereotype.Repository#value() , org.springframework.stereotype.Service#value() , org.springframework.stereotype.Controller#value() , jakarta.inject.Named#value() , FullyQualifiedAnnotationBeanNameGenerator
| Modifier and Type | Field and Description |
|---|---|
| private static final MergedAnnotation. | |
| private static final String | |
| private static final Set | conventionBasedStereotypeCheckCache
Set used to track which stereotype annotations have already been checked
to see if they use a convention-based override for the |
| public static final AnnotationBeanNameGenerator | INSTANCE
A convenient constant for a default |
| private static final Log | |
| private final Map |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected String | Returns: the default bean name (nevernull)the bean definition to build a bean name for definition, BeanDefinitionRegistry the registry that the given bean definition is being registered with registry)Derive a default bean name from the given bean definition. |
| protected String | Returns: the default bean name (nevernull)the bean definition to build a bean name for definition)Derive a default bean name from the given bean definition. |
| protected String | Returns: the bean name, ornull if none is foundthe annotation-aware bean definition annotatedDef)Derive a bean name from one of the annotations on the class. |
| public String | generateBeanName(BeanDefinition
the bean definition to generate a name for definition, BeanDefinitionRegistry the bean definition registry that the given definition
is supposed to be registered with registry)Implements org. Generate a bean name for the given bean definition. |
| private String | Returns: the explicit bean name, ornull if not foundthe metadata)AnnotationMetadata for the underlying classGet the explicit bean name for the underlying class, as configured via
|
| private Set | |
| protected boolean | Returns: whether the annotation qualifies as a stereotype with component namethe name of the annotation class to check annotationType, Set<String> the names of meta-annotations on the given annotation metaAnnotationTypes, Map<String, Object> the map of attributes for the given annotation attributes)Check whether the given annotation is a stereotype that is allowed
to suggest a component name through its |
| ADAPTATIONS | back to summary |
|---|---|
| private static final MergedAnnotation. | |
| COMPONENT_ANNOTATION_CLASSNAME | back to summary |
|---|---|
| private static final String COMPONENT_ANNOTATION_CLASSNAME | |
| conventionBasedStereotypeCheckCache | back to summary |
|---|---|
| private static final Set<String> conventionBasedStereotypeCheckCache Set used to track which stereotype annotations have already been checked
to see if they use a convention-based override for the
| |
| INSTANCE | back to summary |
|---|---|
| public static final AnnotationBeanNameGenerator INSTANCE A convenient constant for a default
| |
| logger | back to summary |
|---|---|
| private static final Log logger | |
| metaAnnotationTypesCache | back to summary |
|---|---|
| private final Map<String, Set<String>> metaAnnotationTypesCache | |
| AnnotationBeanNameGenerator | back to summary |
|---|---|
| public AnnotationBeanNameGenerator() | |
| buildDefaultBeanName | back to summary |
|---|---|
| protected String buildDefaultBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) Derive a default bean name from the given bean definition. The default implementation delegates to
| |
| buildDefaultBeanName | back to summary |
|---|---|
| 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.
| |
| determineBeanNameFromAnnotation | back to summary |
|---|---|
| protected String determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotatedDef) Derive a bean name from one of the annotations on the class.
| |
| generateBeanName | back to summary |
|---|---|
| public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) Implements org. Doc from org. Generate a bean name for the given bean definition.
| |
| getExplicitBeanName | back to summary |
|---|---|
| private String getExplicitBeanName(AnnotationMetadata metadata) Get the explicit bean name for the underlying class, as configured via
| |
| getMetaAnnotationTypes | back to summary |
|---|---|
| private Set | |
| isStereotypeWithNameValue | back to summary |
|---|---|
| protected boolean isStereotypeWithNameValue(String annotationType, Set<String> metaAnnotationTypes, Map<String, Object> attributes) Check whether the given annotation is a stereotype that is allowed
to suggest a component name through its
| |