diff --git a/spring-context/src/main/java/org/springframework/context/annotation/AnnotationBeanNameGenerator.java b/spring-context/src/main/java/org/springframework/context/annotation/AnnotationBeanNameGenerator.java index 5c834b1e010..7502db9182e 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/AnnotationBeanNameGenerator.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/AnnotationBeanNameGenerator.java @@ -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 " + diff --git a/spring-context/src/test/java/org/springframework/context/annotation/AnnotationBeanNameGeneratorTests.java b/spring-context/src/test/java/org/springframework/context/annotation/AnnotationBeanNameGeneratorTests.java index e8174741824..5d2d23b9c9c 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/AnnotationBeanNameGeneratorTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/AnnotationBeanNameGeneratorTests.java @@ -150,18 +150,14 @@ class AnnotationBeanNameGeneratorTests { assertGeneratedName(RestControllerAdviceClass.class, "myRestControllerAdvice"); } - @Test // gh-34317 + @Test // gh-34317, gh-34346 void generateBeanNameFromStereotypeAnnotationWithStringValueAsExplicitAliasForMetaAnnotationOtherThanComponent() { - // As of Spring Framework 6.2, "enigma" is incorrectly used as the @Component name. - // As of Spring Framework 7.0, the generated name will be "annotationBeanNameGeneratorTests.StereotypeWithoutExplicitName". - assertGeneratedName(StereotypeWithoutExplicitName.class, "enigma"); + assertGeneratedName(StereotypeWithoutExplicitName.class, "annotationBeanNameGeneratorTests.StereotypeWithoutExplicitName"); } - @Test // gh-34317 + @Test // gh-34317, gh-34346 void generateBeanNameFromStereotypeAnnotationWithStringValueAndExplicitAliasForComponentNameWithBlankName() { - // As of Spring Framework 6.2, "enigma" is incorrectly used as the @Component name. - // As of Spring Framework 7.0, the generated name will be "annotationBeanNameGeneratorTests.StereotypeWithGeneratedName". - assertGeneratedName(StereotypeWithGeneratedName.class, "enigma"); + assertGeneratedName(StereotypeWithGeneratedName.class, "annotationBeanNameGeneratorTests.StereotypeWithGeneratedName"); } @Test // gh-34317