title: Start up a @WebServlet BEFORE SpringBootApplication's ApplicationContextInitializer beans are initialized
body: <p>I have a simple @WebServlet defined as follows, whose purpose is to construct a couple of static ApplicationContextInitializer beans, which are then required in my Spring Boot Application (for the record, I am implementing ServletContextListener because I also need to add some attributes to the ServletContext).</p>
  
  <pre><code>@WebServlet(urlPatterns = {"/blah"}, loadOnStartup = -1000)
  public class MyServlet implements ServletContextListener {
  
      @Override
      public void contextInitialized(ServletContextEvent sce) {
          AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(MyConfiguration.class);
          Application.logitContextInitializer = context.getBean(LogitContextInitializer.class);
          Application.configWsClientInitializer = context.getBean(ConfigWsClientInitializer.class);
      }
  
      @Override
      public void contextDestroyed(ServletContextEvent sce) {
      }
  
  }
  </code></pre>
  
  <p>My Spring Boot Application looks like this:</p>
  
  <pre><code>@SpringBootApplication
  public class Application extends SpringBootServletInitializer {
  
      public static LogitContextInitializer logitContextInitializer;
      public static ConfigWsClientInitializer configWsClientInitializer;
  
      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder in) {
          in.application().addInitializers(logitContextInitializer, configWsClientInitializer);
  
          SpringApplicationBuilder applicationBuilder = in.sources(Application.class);
          return applicationBuilder;
      }
  
  }
  </code></pre>
  
  <p>However, when running my application, either by deploying to a dedicated Tomcat Server, or triggering programmatically, e,g.:</p>
  
  <pre><code>    new Application().configure(
              new SpringApplicationBuilder(MyServlet.class, Application.class)).run(args);
  </code></pre>
  
  <p>I cannot find a way to trigger MyServlet to start up <strong>before</strong> the ApplicationContextInitializer beans get initialized. I thought the loadOnStartup property in my @WebServlet might be the answer here but it seems to have no effect.</p>