Across bootstrap

The Across bootstrap is the actual starting of the application. During the bootstrapping phase the entire Spring ApplicationContext hierarchy of an application is created.

Bootstrap phases

A typical Across application has the following bootstrap phases:

  1. The root ApplicationContext is scanned, which includes the configuration of the Across context (represented by the @AcrossApplication annotation).

  2. The AcrossContext bean is created as early as possible:

    • the Across context configuration is analyzed and the modules are ordered according to their dependencies;

    • the different module descriptors are offered a chance to customize the Across context configuration;

    • the parent Across ApplicationContext is created to serve as parent for the ApplicationContext of individual modules;

    • every module creates its own ApplicationContext in the order assigned by the Across context;

    • exposed beans are pushed up the ApplicationContext hierarchy as far as possible.

  3. Other beans in the root ApplicationContext are created; these can optionally use exposed components from the Across modules.

  4. The root ApplicationContext returns and is ready to be used. In case of a Spring Boot application, the Spring ApplicationReadyEvent gets published.

Module bootstrap order

During bootstrap the Across context will inspect the dependencies between modules, and will determine the order in which modules should be started. Once the order has been determined, the modules will be started one by one.

Installers

At several points during bootstrap of an Across context, installers can get executed.

Bootstrap events

During bootstrap, the Across context publishes several events that allow other components to act upon.

Advanced topics

Lifecycle events

When starting an Across context, a number of events are published. These allow you to hook into the Across context lifecycle.

AcrossModuleBeforeBootstrapEvent

Event that is sent for each module, right before it is bootstrapped. The configuration of the module can still be modified at this point. Modules will only receive this event for other modules that are started later during the bootstrap phase.

AcrossModuleBootstrappedEvent

Event published when a module has bootstrapped. That means the module itself has started, but installers attached to the AfterModuleBootstrap phase have not yet been executed. Modules will only receive this event for other modules that are started later during the bootstrap phase.

AcrossContextBootstrappedEvent

Event published after the AcrossContext has bootstrapped. That means full initialization has happened: all modules are started and all installers have been executed.

Because of component creation order, lifecycle events can often not be handled using regular @EventListener methods. You should provide an ApplicationListener component for those events instead. A general purpose interface AcrossLifecycleListener can be implemented if you want to handle more than one lifecycle event.

Customizing modules before starting

It is possible to customize an Across context configuration after the modules have been assembled, but before the actual context or module starts. There are two common ways to do this:

  1. handling the AcrossModuleBeforeBootstrapEvent and customizing the configuration of the module being started

  2. providing one or more AcrossBootstrapConfigurer components in the parent ApplicationContext

    • for example: have your @AcrossApplication annotated class implement the AcrossBootstrapConfigurer interface

    • this strategy is often used for providing auto-configuration support of third-party libraries

Additionally, a shared module can also modify the Across context configuration by implementing prepareForBootstrap() on its module descriptor.

Across core events

The following is a listing of all events published by Across core when starting the application.

Table 1. Core events
Event type Description

AcrossModuleBeforeBootstrapEvent

Event that is sent right before the module is bootstrapped. The configuration of the module can still be modified at this point.

AcrossModuleBootstrappedEvent

Event published when a module has bootstrapped. That means the module itself has started, but installers attached to the AfterModuleBootstrap phase have not yet been executed.

AcrossContextBootstrappedEvent

Event published after the AcrossContext has bootstrapped. That means full initialization has happened: all modules are started and all installers have been executed.