concept @startup in category seam

appears as: @Startup
Seam in Action

This is an excerpt from Manning's book Seam in Action.

As soon as Seam is called into action, it begins scanning the classpath for components. The component scanner places the definition for components that it locates into the Seam container. Any components marked as application-scoped startup components (i.e., annotated with both @Startup and @Scope (ScopeType.APPLICATION)) are automatically instantiated by Seam at this time. Startup components are ideal for performing “bootstrap” logic, such as updating the database or registering modules.

The SeamListener also captures notifications when new HTTP sessions are started, at which time it instantiates startup components that reside in the session scope (i.e., annotated with both @Startup and @Scope(ScopeType.SESSION)). All other components are instantiated on demand during the processing of an HTTP request. You’ll learn all about components and how Seam locates, starts, and manages them in the next chapter.

4.5.4. Instantiating components at @Startup

The @Startup annotation, summarized in table 4.10, instructs Seam to take the initiative of creating an instance of the component when the component’s scope is initialized. At the time of this writing, only application- and session-scoped components can be flagged as startup components, though other scopes may be added in the future.

Table 4.10. The @Startup annotation
Name: Startup
Purpose: Instructs the container to eagerly instantiate a component at system initialization for application-scoped components or when the session starts for session-scoped components.
Target: TYPE (class)
Attribute Type Function
depends String[] The names of other components that should be started before this one, if they’re available. Dependencies must be in the same scope as the component itself. Default: none.

If you add the @Startup annotation to the class definition of a component, and the component is scoped to the application context, Seam automatically creates an instance of the component when the application starts. This eager instantiation is consistent with the default behavior of singleton Spring beans. The instance is available as a context variable for the lifetime of the container and thus doesn’t have to be instantiated when requested. The @Startup annotation is well suited for components that use the singleton design pattern.