-
Couldn't load subscription status.
- Fork 38.8k
Description
Sam Brannen opened SPR-13325 and commented
Status Quo
Spring Framework 4.2 introduced support for explicit attribute overrides in meta-annotations via the @AliasFor annotation.
For example, the following @MyTestConfig annotation uses @AliasFor to explicitly override the locations attribute in @ContextConfiguration, effectively renaming it.
@ContextConfiguration
public @interface MyTestConfig {
@AliasFor(annotation = ContextConfiguration.class, attribute = "locations")
String[] xmlFiles();
}@MyTestConfig works fine as long as there is not more than one meta-annotation with an attribute named locations.
In contrast, the following currently does not work.
@ContextConfiguration
@TestPropertySource(locations = "test.properties")
public @interface MyCombinedTestConfig {
@AliasFor(annotation = ContextConfiguration.class, attribute = "locations")
String[] xmlFiles();
}@MyCombinedTestConfig(xmlFiles = "test.xml")
public class MyTests {
// ...
}The reason is that the getAliasedAttributeName(Method attribute, Class<? extends Annotation> targetAnnotationType) method in AnnotationUtils does not verify that the supplied attribute actually declares an alias for the targetAnnotationType. Consequently, a lookup for the locations attribute in @TestPropertySource on MyTests will incorrectly return "test.xml" instead of "test.properties".
Deliverables
- Ensure that an explicit annotation attribute override configured via
@AliasForis only applied to the configured target meta-annotation.
Affects: 4.2 GA
Issue Links:
- Support implicit attribute aliases with @AliasFor [SPR-13345] #17929 Support implicit attribute aliases with
@AliasFor("is depended on by")