Annotation Type DefaultBean


  • @Retention(RUNTIME)
    @Target({METHOD,TYPE,FIELD})
    public @interface DefaultBean
    If a bean is annotated with this annotation, it means that the bean will only be used as a default bean if no other bean of this type is configured. If other another bean is configured however, the default bean is not used. Here is an example:
     @Dependent
     public class SomeConfiguration {
    
         @Produces
         @DefaultBean
         public MyBean create() {
             // create bean
         }
     }
     
    If this code is used and MyBean is not defined anywhere else, then the result of create() is used in all injection points. However, if there is another piece of configuration code that looks like:
     @Dependent
     public class SomeOtherConfiguration {
    
         @Produces
         public MyBean override() {
             // create bean
         }
     }
     
    Then the result of override will be used as a MyBean in all injection points