title: JSF not loading managed beans
body: <p>I got a simple demo project with embedded Jetty and JSF (Primefaces). The problem is that my beans are not loaded at all.</p>
  
  <p>/src/main/java/HelloBean.java</p>
  
  <pre><code>import java.io.Serializable;
  
  import javax.annotation.PostConstruct;
  import javax.annotation.PreDestroy;
  import javax.faces.bean.ApplicationScoped;
  import javax.faces.bean.ManagedBean;
  
  @ManagedBean(eager=true)
  @ApplicationScoped
  public class HelloBean implements Serializable {
  
      private static final long serialVersionUID = 1L;
      ... 
  
      @PreDestroy
      public void preDestroy(){
          System.out.println("PRE DESTROY");
      }
  
      @PostConstruct
      public void postConstruct(){
          System.out.println("POST CONSTRUCT");
      }
  
      public HelloBean() {
          System.out.println("Hello Bean instantiated");
      }
      ...
  }
  </code></pre>
  
  <p>/src/main/webapp/index.xhtml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"&gt;
  
  &lt;h:head&gt;
      &lt;title&gt;Conti Diagnose&lt;/title&gt;
  &lt;/h:head&gt;
  &lt;h:body&gt;
      &lt;h:outputText value="#{helloBean.name}"/&gt;
  ...
  </code></pre>
  
  <p>/src/main/webapp/WEB-INF/web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
  &lt;web-app xmlns="http://java.sun.com/xml/ns/j2ee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
      version="2.4"&gt;
  
      &lt;display-name&gt;Archetype Created Web Application&lt;/display-name&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;javax.faces.PROJECT_STAGE&lt;/param-name&gt;
          &lt;param-value&gt;Development&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;primefaces.THEME&lt;/param-name&gt;
          &lt;param-value&gt;dark-hive&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;com.sun.faces.config.ConfigureListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/faces/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;*.xhtml&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;session-config&gt;
          &lt;session-timeout&gt;
              30
          &lt;/session-timeout&gt;
      &lt;/session-config&gt;
  
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;faces/index.xhtml&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>/src/main/webapp/WEB-INF/faces-config.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;faces-config xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
      http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
      version="2.0"&gt;
      &lt;application&gt;
          &lt;locale-config&gt;
              &lt;default-locale&gt;de&lt;/default-locale&gt;
          &lt;/locale-config&gt;
          &lt;resource-bundle&gt;
              &lt;base-name&gt;lang.lang&lt;/base-name&gt;
              &lt;var&gt;msg&lt;/var&gt;
          &lt;/resource-bundle&gt;
      &lt;/application&gt;
  &lt;/faces-config&gt;
  </code></pre>
  
  <p>The output is</p>
  
  <pre><code>2014-10-30 10:13:11.525:INFO::main: Logging initialized @164ms
  2014-10-30 10:13:11.633:INFO:oejs.Server:main: jetty-9.3.0.M0
  Okt 30, 2014 10:13:11 AM com.sun.faces.config.ConfigureListener contextInitialized
  INFORMATION: Mojarra 2.2.8-02 ( 20140915-1602 https://svn.java.net/svn/mojarra~svn/tags/2.2.8-02@13678) für Kontext '/ui' wird initialisiert.
  Okt 30, 2014 10:13:12 AM com.sun.faces.spi.InjectionProviderFactory createInstance
  INFORMATION: JSF1048: PostConstruct/PreDestroy-Annotationen vorhanden.  Verwaltete Bean-Methoden, die mit diesen Annotationen markiert sind, lassen die entsprechenden Annotationen verarbeiten.
  Okt 30, 2014 10:13:13 AM com.sun.faces.config.ConfigureListener$WebConfigResourceMonitor$Monitor &lt;init&gt;
  INFORMATION: Monitoring file:/C:/.../src/main/webapp/WEB-INF/faces-config.xml for modifications
  Okt 30, 2014 10:13:13 AM org.primefaces.webapp.PostConstructApplicationEventListener processEvent
  INFORMATION: Running on PrimeFaces 5.1
  2014-10-30 10:13:13.157:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@538540a3{/ui,[file:///.../target/classes/../../src/main/webapp/, file:///.../target/],AVAILABLE}
  2014-10-30 10:13:13.221:INFO:oejs.ServerConnector:main: Started ServerConnector@5aa85b18{HTTP/1.1}{localhost:8080}
  2014-10-30 10:13:13.222:INFO:oejs.Server:main: Started @1864ms
  </code></pre>
  
  <p>The class to start the embedded server is /src/main/JettyRunner.java. The main method is:</p>
  
  <pre><code>InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 8080);
  Server server = new Server(address);
  
  WebAppContext wac = new WebAppContext();
  wac.setContextPath("/ui");
  wac.setWelcomeFiles(new String[] { "index.xhtml" });
  String webappDir=JettyRunner.class.getClassLoader().getResource(".").toString();
  wac.setBaseResource(new ResourceCollection(new String[] {
          webappDir+"../../src/main/webapp","./target" }));
  
  server.setHandler(wac);
  server.setStopAtShutdown(true);
  server.start();
  server.join();
  </code></pre>
  
  <p>The messages in postConstruct or the Constructor are not printed at all. Accessing a property of this bean in my xhtml gives no error and just prints nothing.</p>
  
  <p>Even if I access a bean that does not exist, there's no error message.</p>
  
  <p>Why are my beans not loaded?</p>