Annotation Type Startup

  • @Documented
    public @interface Startup

    Stereo type that designates a bean as an eagerly instantiated bean with application scope. Watch out with IDE autocomplete on import that you don't accidentally import EJB's one.

     import org.omnifaces.cdi.Startup;
     public class MyStartupBean {}

    In effect, this annotation does exactly the same as:

     import jakarta.enterprise.context.ApplicationScoped;
     import org.omnifaces.cdi.Eager;
     public class MyStartupBean {}

    This bean type effectively functions as a CDI based startup listener for the web application.

    Note that Java EE thus also provides the jakarta.ejb.Startup and jakarta.ejb.Singleton annotations which together provide similar functionality, but it requires an EJB dependency (which may not be applicable on e.g. Tomcat+Weld) and it will result in the bean annotated with these annotations to become an EJB session bean (with automatic transaction management and automatic locking which you might need to turn off with yet more additional jakarta.ejb.TransactionAttribute and jakarta.ejb.Lock annotations if these are not appropriate for some situation).

    Arjan Tijms