2.4.1.1. Nablarch Servlet Context Initialization Listener

This class is defined as a servlet context listener, and performs the following operations when the launching or exiting the web application.

At startup
At completion

2.4.1.1.1. Module list

<dependency>
  <groupId>com.nablarch.framework</groupId>
  <artifactId>nablarch-fw-web</artifactId>
</dependency>
<dependency>
  <groupId>com.nablarch.framework</groupId>
  <artifactId>nablarch-core</artifactId>
</dependency>
<dependency>
  <groupId>com.nablarch.framework</groupId>
  <artifactId>nablarch-core-repository</artifactId>
</dependency>
<dependency>
  <groupId>com.nablarch.framework</groupId>
  <artifactId>nablarch-core-applog</artifactId>
</dependency>

2.4.1.1.2. Initializing the system repository

To initialize the system repository, the following must be configured.

  • This class is registered as a servlet context listener.
  • The path of the component configuration file is configured as an initialization parameter of the servlet context.

A configuration example for web.xml is shown below.

Point
  • The parameter name of the path of the component configuration file should be di.config .
<context-param>
  <param-name>di.config</param-name>
  <param-value>web-boot.xml</param-value>
</context-param>

<listener>
  <listener-class>nablarch.fw.web.servlet.NablarchServletContextListener</listener-class>
</listener>

2.4.1.1.3. Get the success or failure of the initialization in the subsequent process

Whether the initialization of this class has succeeded or not can be obtained by using NablarchServletContextListener#isInitializationCompleted. If the initialization is successful, the above method returns true.

If the initialization of this class fails, the application will also fail to start, but if multiple servlet context listeners have been registered, the processing of the servlet context listeners following this class may be executed. This function makes it possible for the servlet context listener after this class to make a branch that continues processing only if the system repository is successfully initialized, as follows.

public class CustomServletContextListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        if(NablarchServletContextListener.isInitializationCompleted()){
          // Processing using the system repository
        }
    }

The order of execution of servlet context listeners is the order described in web.xml. If you register a servlet context listener that uses the system repository, you need to describe it in web.xml after this class as follows. Also, the order of execution is not guaranteed when registering servlet context listener by @WebListener annotation, so be sure to define it in web.xml.

<listener>
  <listener-class>nablarch.fw.web.servlet.NablarchServletContextListener</listener-class>
</listener>
<listener>
  <listener-class>please.change.me.CustomServletContextListener</listener-class>
</listener>

Tip

When multiple servlet context listeners are registered, whether to detect an exception in the processing of the previously executed servlet context listener and abort the processing, or to ignore the exception and continue the processing of the subsequent servlet context listener depends on the implementation of the servlet container.