Skip to content

Package tangle in org.springframework.core [SPR-13153] #17744

Closed

Description

@spring-projects-issues

Stéphane Nicoll opened SPR-13153 and commented

Status Quo

Commit 518c85b introduced a package tangle resulting from MethodParameter's new dependency on AnnotationUtils.

Analysis

MethodParameter now uses AnnotationUtils in order to support annotation attribute aliases via @AliasFor. Without this functionality, many of the aliases for value attributes cannot be supported in annotations on methods and method parameters. For example, the following (amongst others) rely on this support:

| spring-messaging | @Header |
| spring-messaging | @Payload |
| spring-messaging | @SendToUser |
| spring-web | @CookieValue |
| spring-web | @MatrixVariable |
| spring-web | @RequestHeader |
| spring-web | @RequestParam |
| spring-web | @RequestPart |
| spring-web | @ResponseStatus |

However, AnnotationUtils already has a dependency on BridgeMethodResolver which resides in the core package alongside MethodParameter, and this causes the package cycle.

Proposals

  1. Refactor MethodParameter to use reflection to invoke utility methods in AnnotationUtils.
  2. Refactor AnnotationUtils to use reflection to invoke utility methods in BridgeMethodResolver.
  3. Introduce subclass of MethodParameter in package org.springframework.core.annotation with support for synthesizing annotations.
    • Proposed name: SynthesizingMethodParameter

Affects: 4.2 RC2

Issue Links:

Referenced from: commits dc1f921

Activity

  1. spring-projects-issues commented on Jun 29, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Alright, the SynthesizingMethodParameter approach is coming to master now... selectively used for web and message handler methods at this point, with other areas such as qualifier matching still using the basic MethodParameter class with raw annotation exposure.

    Juergen

  2. spring-projects-issues commented on Jun 30, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Thanks for implementing the SynthesizingMethodParameter approach!

    That turned out to be quite an elegant solution to the problem.

  3. spring-projects-issues commented on Jun 30, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    FYI: for anyone else following this issue, I'd just like to point out that attempting to synthesize an annotation is exactly that, an attempt.

    If an annotation is not synthesizable (i.e., does not make use of @AliasFor) then Spring simply does not synthesize it. In other words, if you directly invoke one of the synthesizeAnnotation*(..) methods in AnnotationUtils (or indirectly via SynthesizingMethodParameter or AnnotatedElementUtils), Spring will only synthesize the annotation if it's necessary; otherwise, Spring simply returns the original (raw) annotation as is.

    Regards,

    Sam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type: task

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions