Spring Framework
  1. Spring Framework
  2. SPR-9890

Allow usage of injection annotations (@Autowired, @Value) as meta-annotations

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Complete
    • Affects Version/s: None
    • Fix Version/s: 3.2 RC1
    • Component/s: Core:DI
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      Assuming libraries expose primitive values as Spring beans under well-defined names like foo.bar. They couldbe used by clients using @Value("foo.bar"), which is reasonable but error- prone. It would be cool if you could use @Value as follows:

      @Target(ElementType.FIELD)
      @Retention(RetentionPolicy.RUNTIME)
      @Value("foo.bar")
      public @interface MySpecialValue { }
      

      This allows clients to use @MySpecialValue for injection and thus prevent
      potential typos. Implementing the same for @Autowired would naturally complete the meta-annotation usage of @Qualifier as you can go from:

      @Target(ElementType.FIELD)
      @Retention(RetentionPolicy.RUNTIME)
      @Qualifier("myQualifier")
      public @interface MyQualifier { }
      

      and

      @Autowired
      @MyQualifier
      Dependency dependency;
      

      to

      @Target(ElementType.FIELD)
      @Retention(RetentionPolicy.RUNTIME)
      @Qualifier("myQualifier")
      @Autowired
      public @interface MyQualifiedAutowire { }
      

      and

      @MyQualifiedAutowiring
      Dependency dependency
      

        Activity

        Hide
        Oliver Gierke added a comment -
        Show
        Oliver Gierke added a comment - Pull request submitted: https://github.com/SpringSource/spring-framework/pull/168 /cc Juergen Hoeller
        Show
        Sam Brannen added a comment - Resolving this issue as Complete since it was apparently addressed in the following GitHub commits. https://github.com/SpringSource/spring-framework/commit/208152169567a6f13d4a04d29e3e968e406ed26e https://github.com/SpringSource/spring-framework/commit/914a1b208869102da76832fb7f99e1bbfc2c5f6e

          People

          • Assignee:
            Juergen Hoeller
            Reporter:
            Oliver Gierke
            Last updater:
            Chris Beams
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              1 year, 25 weeks, 1 day ago