Skip to content

Support repeatable annotations as composed annotations [SPR-13973] #18545

Closed
@spring-projects-issues

Description

@spring-projects-issues

Phil Webb opened SPR-13973 and commented

Given the following annotations:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface MockBeans {

	MockBean[] value();
}
@Target({ ElementType.TYPE, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Repeatable(MockBeans.class)
public @interface MockBean {

	@AliasFor("classToMock")
	Class<?> value() default Void.class;

	@AliasFor("value")
	Class<?> classToMock() default Void.class;
}
@Target({ ElementType.TYPE, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@MockBean
public @interface MyMockBean {

	@AliasFor(annotation = MockBean.class)
	Class<?> value();
}

And the following class:

@MyMockBean(ExampleService.class)
static class MetaMockBean {
}

Calling AnnotationUtils.getRepeatableAnnotations(MetaMockBean.class,MockBean.class, MockBeans.class) will return a synthesized annotation. However, calling value() on the result returns Void.class rather than the expected ExampleService.class.

Is this expected behavior?


Affects: 4.2.4

Issue Links:

Referenced from: commits 4836d06, 46e0484, 2ed3382, b0c6357, c6f6e19, 3597879, d572b02, 2535469, 4fa11e3, c6b1f38, 4742aa0, b6d9fd3

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions