Skip to content

Introduce unified support for declaring and looking up annotation attribute aliases [SPR-11512] #16137

Closed
@spring-projects-issues

Description

@spring-projects-issues

Sam Brannen opened SPR-11512 and commented

Status Quo

Limited support for annotation attribute aliases already exists in the Spring Framework but is scattered across various modules. Currently, the following annotations are known to support aliases:

  • @ManagedResource
  • @ActiveProfiles
  • @ContextConfiguration
  • @Sql
  • @TestExecutionListeners
  • @TestPropertySource
  • @ControllerAdvice

Goal

The goal of this issue is to introduce unified support for declaring and looking up annotation attribute aliases (within a given annotation).


Deliverables

All annotations introduced in conjunction with this issue must reside in the org.springframework.core.annotation package.

  1. Introduce an annotation that can be declared on annotation attributes to indicate that the given attribute is an alias for another attribute of the same type within the same annotation class.
    • Proposed name: @AliasFor
  2. Consider introducing another annotation to be used on the aliased attribute itself in order to provide a two-way link between all such aliases.
    • Proposed name: @AliasedBy
  3. Extract code from the TestContext framework that is responsible for handling the look-up of annotation aliases and incorporate this code in a generic fashion in AnnotationUtils and AnnotatedElementUtils as appropriate.
    • This new look-up mechanism must be based on the annotation introduced in deliverable Spring core JMS pom.xml #1.
    • If multiple values for an aliased attribute are present in a declared annotation, an AnnotationConfigurationException must be thrown indicating that only one attribute for an aliased attribute may be specified in a concrete instance of the given annotation.
    • See also the current implementations for attribute aliases related to @ControllerAdvice and @ManagedResource.
  4. Migrate all existing code that supports attribute aliases to use this new mechanism.

Example: Modified @ContextConfiguration Declaration

The following demonstrates how @ContextConfiguration could be rewritten to take advantage of the functionality proposed by this issue.

public @interface ContextConfiguration {

    @AliasedBy("locations")
    String[] value() default {};

    @AliasFor("value")
    String[] locations() default {};

    // ...
}

Affects: 4.0 GA

Issue Links:

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