Class SpringBootBootstrappingServletContextListener

java.lang.Object
org.broadleafcommerce.common.web.boot.support.SpringBootBootstrappingServletContextListener
All Implemented Interfaces:
jakarta.servlet.ServletContextListener, EventListener

public class SpringBootBootstrappingServletContextListener extends Object implements jakarta.servlet.ServletContextListener

Bootstraps a Spring Boot application using a ServletContextListener rather than the default of using a ServletContextInitializer. The use case here is when you absolutely have to use a web.xml and cannot rely on classpath scanning for a ServletContextInitializer

This is designed to work in conjunction with the BroadleafBootServletContextInitializer (although not requried) which serves as a drop-in replacement for SpringBootServletInitializer.

Given an application that looks like this:

 package com.mycompany

 @SpringBootApplication
 public class MyApplication extends BroadleafBootServletContextInitializer {

 }
 

A web.xml should contain the following listener configuration:

 
 <context-param>
   <param-name>listenerContextInitializerClass</param-name>
  <param-value>com.mycompany.MyApplication</param-value>
 </context-param>
 <listener>
   <listener-class>org.broadleafcommerce.common.web.boot.support.SpringBootBootstrappingServletContextListener</listener-class>
 </listener>
 
 
Author:
Phillip Verheyden (phillipuniverse)
See Also:
  • Field Details

    • APPLICATION_CLASS

      public static final String APPLICATION_CLASS
      See Also:
    • delegateListener

      protected org.springframework.web.context.ContextLoaderListener delegateListener
  • Constructor Details

    • SpringBootBootstrappingServletContextListener

      public SpringBootBootstrappingServletContextListener()
  • Method Details

    • contextInitialized

      public void contextInitialized(jakarta.servlet.ServletContextEvent event)
      Specified by:
      contextInitialized in interface jakarta.servlet.ServletContextListener
    • contextDestroyed

      public void contextDestroyed(jakarta.servlet.ServletContextEvent event)
      Specified by:
      contextDestroyed in interface jakarta.servlet.ServletContextListener
    • getInitializerClass

      protected Class<org.springframework.web.WebApplicationInitializer> getInitializerClass(jakarta.servlet.ServletContext ctx) throws ClassNotFoundException, LinkageError
      Throws:
      ClassNotFoundException
      LinkageError
    • createInitializer

      protected org.springframework.web.WebApplicationInitializer createInitializer(Class<org.springframework.web.WebApplicationInitializer> initializerClass) throws PrivilegedActionException
      Throws:
      PrivilegedActionException