Annotation Interface Startup


@Target({TYPE,METHOD,FIELD}) @Retention(RUNTIME) public @interface Startup
This annotation can be used to initialize a CDI bean at application startup:
  • If a bean class is annotated then a contextual instance is created and the PostConstruct callbacks are invoked.
  • If a producer method is annotated then a contextual instance is created, i.e. the producer method is invoked.
  • If a producer field is annotated then a contextual instance is created, i.e. the producer field is read.
  • If a non-static non-producer no-args method of a bean class is annotated then a contextual instance is created, the lifecycle callbacks are invoked and finally the method itself is invoked.
  • The behavior is similar to a declaration of a StartupEvent observer. In fact, a synthetic observer of the StartupEvent is generated for each occurence of this annotation.

    Furthermore, value() can be used to specify the priority of the generated observer method and thus affects observers ordering.

    The contextual instance is destroyed immediately after the method is invoked for Dependent beans.

    The following examples are functionally equivalent.

     @ApplicationScoped
     class Bean1 {
         void onStart(@Observes StartupEvent event) {
             // place the logic here
         }
     }
    
     @Startup
     @ApplicationScoped
     class Bean2 {
    
         @PostConstruct
         void init() {
             // place the logic here
         }
     }
    
     @ApplicationScoped
     class Bean3 {
    
         @Startup
         void init() {
             // place the logic here
         }
     }
     
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    int
     
  • Element Details

    • value

      int value
      Returns:
      the priority
      See Also:
      • Priority
      Default:
      2500