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:
-
The root
ApplicationContext
is scanned, which includes the configuration of the Across context (represented by the@AcrossApplication
annotation). -
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 theApplicationContext
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.
-
-
Other beans in the root
ApplicationContext
are created; these can optionally use exposed components from the Across modules. -
The root
ApplicationContext
returns and is ready to be used. In case of a Spring Boot application, the SpringApplicationReadyEvent
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:
-
handling the
AcrossModuleBeforeBootstrapEvent
and customizing the configuration of the module being started -
providing one or more
AcrossBootstrapConfigurer
components in the parentApplicationContext
-
for example: have your
@AcrossApplication
annotated class implement theAcrossBootstrapConfigurer
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.
Event type | Description |
---|---|
|
Event that is sent right before the module is bootstrapped. The configuration of the module can still be modified at this point. |
|
Event published when a module has bootstrapped.
That means the module itself has started, but installers attached to the |
|
Event published after the AcrossContext has bootstrapped. That means full initialization has happened: all modules are started and all installers have been executed. |