title: Load data on Spring Boot application startup
body: <p>I wish to load some data on application-startup and store them in a global context so that all my configuration and controller classes can read those data from the context.</p>
  
  <p>Traditionally, I use a <code>ServletContextListener</code> to load the data in <code>contextInitialized</code> method and store them in <code>ServletContext</code>. For example,</p>
  
  <pre><code>public void contextInitialized(ServletContextEvent event) {
      // load data
      event.getServletContext()..setAttribute(...)
  }
  </code></pre>
  
  <p>And in my controllers I just inject the <code>ServletContext</code> or make my controller implement <code>ServletContextAware</code>.</p>
  
  <p>What is the Spring Boot way of achieving this? I can think of the below options, but not completely sure how to use these for my use-case.</p>
  
  <ul>
  <li><code>@PostConstruct</code> (on which bean?)</li>
  <li><code>@Configuration</code> (load the data and return as a <code>@Bean</code>?)</li>
  <li><code>ApplicationListener</code> or <code>@EventListener</code> that listens on <code>ContextRefreshedEvent</code> or <code>ApplicationReadyEvent</code> (how to expose the data to my controllers? I also want the data on my <code>@Configuration</code> class. But these events occur after beans defined in <code>@Configuration</code> are already created)</li>
  </ul>