1
1
/*
2
- * Copyright 2002-2024 the original author or authors.
2
+ * Copyright 2002-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -150,6 +150,25 @@ void generateBeanNameFromSubStereotypeAnnotationWithStringArrayValueAndExplicitC
150
150
assertGeneratedName (RestControllerAdviceClass .class , "myRestControllerAdvice" );
151
151
}
152
152
153
+ @ Test // gh-34317
154
+ void generateBeanNameFromStereotypeAnnotationWithStringValueAsExplicitAliasForMetaAnnotationOtherThanComponent () {
155
+ // As of Spring Framework 6.2, "enigma" is incorrectly used as the @Component name.
156
+ // As of Spring Framework 7.0, the generated name will be "annotationBeanNameGeneratorTests.StereotypeWithoutExplicitName".
157
+ assertGeneratedName (StereotypeWithoutExplicitName .class , "enigma" );
158
+ }
159
+
160
+ @ Test // gh-34317
161
+ void generateBeanNameFromStereotypeAnnotationWithStringValueAndExplicitAliasForComponentNameWithBlankName () {
162
+ // As of Spring Framework 6.2, "enigma" is incorrectly used as the @Component name.
163
+ // As of Spring Framework 7.0, the generated name will be "annotationBeanNameGeneratorTests.StereotypeWithGeneratedName".
164
+ assertGeneratedName (StereotypeWithGeneratedName .class , "enigma" );
165
+ }
166
+
167
+ @ Test // gh-34317
168
+ void generateBeanNameFromStereotypeAnnotationWithStringValueAndExplicitAliasForComponentName () {
169
+ assertGeneratedName (StereotypeWithExplicitName .class , "explicitName" );
170
+ }
171
+
153
172
154
173
private void assertGeneratedName (Class <?> clazz , String expectedName ) {
155
174
BeanDefinition bd = annotatedBeanDef (clazz );
@@ -192,15 +211,15 @@ static class ComponentWithMultipleConflictingNames {
192
211
@ Retention (RetentionPolicy .RUNTIME )
193
212
@ Component
194
213
@interface ConventionBasedComponent1 {
195
- // This intentionally convention-based. Please do not add @AliasFor.
214
+ // This is intentionally convention-based. Please do not add @AliasFor.
196
215
// See gh-31093.
197
216
String value () default "" ;
198
217
}
199
218
200
219
@ Retention (RetentionPolicy .RUNTIME )
201
220
@ Component
202
221
@interface ConventionBasedComponent2 {
203
- // This intentionally convention-based. Please do not add @AliasFor.
222
+ // This is intentionally convention-based. Please do not add @AliasFor.
204
223
// See gh-31093.
205
224
String value () default "" ;
206
225
}
@@ -242,7 +261,7 @@ private static class ComponentFromNonStringMeta {
242
261
@ Target (ElementType .TYPE )
243
262
@ Controller
244
263
@interface TestRestController {
245
- // This intentionally convention-based. Please do not add @AliasFor.
264
+ // This is intentionally convention-based. Please do not add @AliasFor.
246
265
// See gh-31093.
247
266
String value () default "" ;
248
267
}
@@ -301,7 +320,6 @@ static class ComposedControllerAnnotationWithStringValue {
301
320
String [] basePackages () default {};
302
321
}
303
322
304
-
305
323
@ TestControllerAdvice (basePackages = "com.example" , name = "myControllerAdvice" )
306
324
static class ControllerAdviceClass {
307
325
}
@@ -310,4 +328,56 @@ static class ControllerAdviceClass {
310
328
static class RestControllerAdviceClass {
311
329
}
312
330
331
+ @ Retention (RetentionPolicy .RUNTIME )
332
+ @ Target (ElementType .ANNOTATION_TYPE )
333
+ @interface MetaAnnotationWithStringAttribute {
334
+
335
+ String attribute () default "" ;
336
+ }
337
+
338
+ /**
339
+ * Custom stereotype annotation which has a {@code String value} attribute that
340
+ * is explicitly declared as an alias for an attribute in a meta-annotation
341
+ * other than {@link Component @Component}.
342
+ */
343
+ @ Retention (RetentionPolicy .RUNTIME )
344
+ @ Target (ElementType .TYPE )
345
+ @ Component
346
+ @ MetaAnnotationWithStringAttribute
347
+ @interface MyStereotype {
348
+
349
+ @ AliasFor (annotation = MetaAnnotationWithStringAttribute .class , attribute = "attribute" )
350
+ String value () default "" ;
351
+ }
352
+
353
+ @ MyStereotype ("enigma" )
354
+ static class StereotypeWithoutExplicitName {
355
+ }
356
+
357
+ /**
358
+ * Custom stereotype annotation which is identical to {@link MyStereotype @MyStereotype}
359
+ * except that it has a {@link #name} attribute that is an explicit alias for
360
+ * {@link Component#value}.
361
+ */
362
+ @ Retention (RetentionPolicy .RUNTIME )
363
+ @ Target (ElementType .TYPE )
364
+ @ Component
365
+ @ MetaAnnotationWithStringAttribute
366
+ @interface MyNamedStereotype {
367
+
368
+ @ AliasFor (annotation = MetaAnnotationWithStringAttribute .class , attribute = "attribute" )
369
+ String value () default "" ;
370
+
371
+ @ AliasFor (annotation = Component .class , attribute = "value" )
372
+ String name () default "" ;
373
+ }
374
+
375
+ @ MyNamedStereotype (value = "enigma" , name ="explicitName" )
376
+ static class StereotypeWithExplicitName {
377
+ }
378
+
379
+ @ MyNamedStereotype (value = "enigma" )
380
+ static class StereotypeWithGeneratedName {
381
+ }
382
+
313
383
}
0 commit comments