Annotation Interface 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 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 MyBean in all injection points.

Default beans can optionally declare Priority. In case there is no priority defined, @Priority(0) is assumed. Priority value is used for bean ordering and during typesafe resolution to disambiguate multiple matching default beans.