Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-9890

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

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: 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
      

        Attachments

          Activity

            People

            • Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              olivergierke Oliver Gierke
              Last updater:
              Chris Beams
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                5 years, 37 weeks, 5 days ago