Annotation Type ExcludedFromAutowiring


  • @Retention(RUNTIME)
    @Target(TYPE)
    @Inherited
    public @interface ExcludedFromAutowiring
    Use this annotation in the bean implementation class to make base interfaces of the bean be ignored from default Spring autowiring.
    Let's consider an example:
            IBase
          /      \
       BaseImpl   \
                 IChild
                   \
                 MegaImpl
     
    Here IBase and IChild are interface, BaseImpl and MegaImpl are implementation classes. Once you register BaseImpl and MegaImpl as Spring beans you need to make either BaseImpl or MegaImpl as autowire-candidate='false'
    We are likely to make Spring autowire BaseImpl to all dependencies that require IBase and to autowire MegaImpl to all dependencies that require IChild. This would simplify runtime dependencies of the application
    Sill, the only possible solution with autowire-candidate='false' is to make Spring autowire MegaImpl for all IChild and IBase dependencies.
    It is also possible to use primary='true' in BaseImpl declaration, in order to implement right behaviour, but this approach does not scale to the case you need to have more than 2 bean implementations (i.e. we have MegaMegaImpl and IChildChild)
    To use the annotation you need to add it to MegaImpl to declare it should not be autowired for IBase interface dependency.
    For more details on Spring see the doc
    Since:
    8.0
    Author:
    Maxim.Manuylov, Eugene.Petrenko Dante: 23.10.12
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      java.lang.Class<?>[] types
      Types for which the annotated bean should not be an autowire candidate
    • Element Detail

      • types

        @NotNull
        java.lang.Class<?>[] types
        Types for which the annotated bean should not be an autowire candidate
        Returns:
        array of interfaces
        Since:
        8.0