title: Load Applicationscoped Bean with ServletContext
body: <p>I have created a class StartupListener implements ServletContextListener. Inside </p>
  
  <pre><code>@Override
  public void contextInitialized(ServletContextEvent contextEvent) {
  </code></pre>
  
  <p>I create a timer which will be executed every 30 seconds. Inside this timer I want to set a parameter from my @ApplicationScoped - Bean in order to display the information from the timer to my website.</p>
  
  <p>Here is what I did so far:</p>
  
  <p><strong>StartupListener.java</strong></p>
  
  <pre><code>package de.whatever;
  
  import java.util.Timer;
  import javax.naming.Context;
  
  public class CargoServiceStartupListener implements ServletContextListener {
  
  @Override
  public void contextInitialized(ServletContextEvent contextEvent) {
  
      ....        
  
          ModuleScannerTask task = new ModuleScannerTask(contextEvent.getServletContext());
          Timer timer = new Timer("Scanner");
          timer.schedule(task, 0, 10000);
  </code></pre>
  
  <p><strong>ModuleScannerTask.java</strong></p>
  
  <pre><code>package de.whatever;
  
  import java.util.Enumeration;
  
  public class ModuleScannerTask extends TimerTask{
  
  private ServletContext context;
  
  public ModuleScannerTask (ServletContext context) {
      this.context = context;
  }
  
  @Override
  public void run() {
        System.out.println("Start scanning ...");
            ...
  </code></pre>
  
  <p><strong>ModuleBean.java</strong></p>
  
  <pre><code>package de.whatever;
  
  @ManagedBean (name="modOverview")
  @ApplicationScoped
  public class ModuleOverviewBean {
  
  private String randomData;
  </code></pre>
  
  <p>My question is how to set data into <strong>randomData</strong> field in my application bean.</p>
  
  <p>I read that I could load the attribute "modOverview" from the ServletContext, but that returns null.</p>
  
  <p>What would be the correct way to load and set the values?</p>
  
  <p>I am using JBoss (without spring).</p>
  
  <p>Thanks
  Hauke</p>