Stop using explicitly aliased value attribute as @Component name
Prior to this commit, if a custom stereotype annotation was meta-annotated with @Component and declared a local String `value` attribute that was explicitly configured (via @AliasFor) as an override for an attribute other than @Component.value, the local `value` attribute was still used as a convention-based override for @Component.value. Consequently, a local `value` attribute was used as a custom @Component name, even when that is clearly not the intent. To address that, this commit revises the logic in AnnotationBeanNameGenerator so that a `value` attribute which is explicitly aliased to something other than @Component.value is no longer used as an explicit @Component name. See gh-34317 Closes gh-34346
This commit is contained in:
@@ -147,25 +147,16 @@ public class AnnotationBeanNameGenerator implements BeanNameGenerator {
|
||||
key -> getMetaAnnotationTypes(mergedAnnotation));
|
||||
if (isStereotypeWithNameValue(annotationType, metaAnnotationTypes, attributes)) {
|
||||
Object value = attributes.get(MergedAnnotation.VALUE);
|
||||
if (value instanceof String currentName && !currentName.isBlank()) {
|
||||
if (value instanceof String currentName && !currentName.isBlank() &&
|
||||
!hasExplicitlyAliasedValueAttribute(mergedAnnotation.getType())) {
|
||||
if (conventionBasedStereotypeCheckCache.add(annotationType) &&
|
||||
metaAnnotationTypes.contains(COMPONENT_ANNOTATION_CLASSNAME) && logger.isWarnEnabled()) {
|
||||
if (hasExplicitlyAliasedValueAttribute(mergedAnnotation.getType())) {
|
||||
logger.warn("""
|
||||
Although the 'value' attribute in @%s declares @AliasFor for an attribute \
|
||||
other than @Component's 'value' attribute, the value is still used as the \
|
||||
@Component name based on convention. As of Spring Framework 7.0, such a \
|
||||
'value' attribute will no longer be used as the @Component name."""
|
||||
.formatted(annotationType));
|
||||
}
|
||||
else {
|
||||
logger.warn("""
|
||||
Support for convention-based @Component names is deprecated and will \
|
||||
be removed in a future version of the framework. Please annotate the \
|
||||
'value' attribute in @%s with @AliasFor(annotation=Component.class) \
|
||||
to declare an explicit alias for @Component's 'value' attribute."""
|
||||
.formatted(annotationType));
|
||||
}
|
||||
logger.warn("""
|
||||
Support for convention-based @Component names is deprecated and will \
|
||||
be removed in a future version of the framework. Please annotate the \
|
||||
'value' attribute in @%s with @AliasFor(annotation=Component.class) \
|
||||
to declare an explicit alias for @Component's 'value' attribute."""
|
||||
.formatted(annotationType));
|
||||
}
|
||||
if (beanName != null && !currentName.equals(beanName)) {
|
||||
throw new IllegalStateException("Stereotype annotations suggest inconsistent " +
|
||||
|
||||
Reference in New Issue
Block a user