Knowing Liferay’s startup phases helps you troubleshoot startup failures. By learning the phase triggered events, you can listen for phases and act on them. This article describes the startup phases and identifies how to implement actions for phase events.
Startup consists of these main phases:
-
Portal Context Initialization Phase: focuses on low level tasks without a web context.
-
Main Servlet Initialization Phase: focuses on the portlet container and the Liferay DXP web application’s UI features such as Struts, Themes, and more.
The Portal Context Initialization Phase sets the stage for the Main Servlet Initialization Phase.
Portal Context Initialization Phase
The Portal Context Initialization phase runs first with these tasks:
-
Set up low level utilities such as logging and those in
PortalUtil
andInitUtil
. -
OSGi framework is initialized.
-
Spring Phase 1: INFRASTRUCTURE beans specified by the Spring context files listed in Portal property
spring.infrastructure.configs
are loaded. -
INFRASTRUCTURE beans are published as OSGi services.
-
OSGi framework starts.
- Static bundles are installed and started.
- Dynamic bundles are started.
-
OSGi framework starts the runtime.
-
Spring Phase 2: MAIN
- Load Spring beans specified by the Spring context files listed in Portal
property
spring.configs
. - A
ModuleServiceLifecycle
event service with a service propertymodule.service.lifecycle
valuespring.initialized
(i.e.,SPRING_INITIALIZED
) registers.
- Load Spring beans specified by the Spring context files listed in Portal
property
-
MAIN Spring beans are published as OSGi services.
Main Servlet Initialization Phase
Here’s the phase’s activity sequence:
-
The
ModuleServiceLifecycle
event service is updated with the service propertymodule.service.lifecycle
valuedatabase.initialized
(i.e.,DATABASE_INITIALIZED
). -
The Global Startup event fires.
-
For each portal instance, the Application Startup events fire.
-
The
ModuleServiceLifecycle
event service is updated with the service propertymodule.service.lifecycle
valueportal.initialized
(i.e.,PORTAL_INITIALIZED
).
Now that you’re acquainted with the startup phases, you can concentrate on the events they fire.
Acting on Events
The ways to act on events depends on the event type. These subsections describe the event types.
ModuleServiceLifecycle Events
You can wait for and act on ModuleServiceLifecycle
event services.
Portal Startup Events
In your liferay-portal-ext.properties
file, you can override the following
properties and add your own
LifecycleAction
classes to the list of action classes to invoke on the events.
Global Startup Event runs once when Liferay DXP initializes. The
global.startup.events
property
defines the event’s default actions.
Application Startup Events runs once for each Site instance Liferay DXP
initializes. The
application.startup.events
property
defines the event’s default actions.
Related Topics
OSGi Services and Dependency Injection with Declarative Services