title: Cannot instantiate Spring Bean from managed bean , Spring + JSF
body: <p>I created a simple application that s using JSF and managed beans.From the managed bean I m trying to instantiate a spring bean that stores data to the database. However "@Autowired" annotation doesnt seem to work since I get a nullPointerExcpetion. I read all the related topics of how to use JSF and managed beans with Spring but couldnt solve the problem .
  Maybe someone could have a look at the following piece of code and give me a hint?</p>
  
  <pre>
  ########## ManagedBean #########
  
      @Component
      @Scope("request")
      @Qualifier("memberBean")
      public class ProjectEntityHandlerBean
      {
  
        private  List projectList;
  
        @Autowired
        private ProjectBeanLocal projectBean;
  
      public ProjectEntityHandlerBean()
      {
  
      }
  
      public List getProjectList() {  
          return projectList;  
      } 
  
  
          public String getAllProjects()
          {       
              projectList = projectBean.getAllProjects();
              return "true";      
          }
  
  </pre>
  
  <p>The Service Bean</p>
  
  <pre>
  
      @Service
      public class ProjectBean implements ProjectBeanLocal {
  
            @PersistenceContext
            private EntityManager em;
  
          /**
           * Default constructor. 
           */
  
          public ProjectBean() {
              // TODO Auto-generated constructor stub
          }
  
          @Transactional
          public List getAllProjects()
  
          {   
              System.out.println("ProjectBean invoked");
  
              Query query = em.createQuery("SELECT p FROM Project p");
  
              @SuppressWarnings("unchecked")
  
  
  
  
          List projects = query.getResultList();                 
              return projects;
          }
  
  </pre>
  
  <p>The faces.config.xml </p>
  
  <pre><code> &lt;application&gt;
       &lt;el-resolver&gt;org.springframework.web.jsf.el.SpringBeanFacesELResolver&lt;/el-resolver&gt;
      &lt;/application&gt;
  
      &lt;managed-bean&gt;
          &lt;managed-bean-name&gt;loginBean&lt;/managed-bean-name&gt;
          &lt;managed-bean-class&gt;com.example.controller.LoginBean&lt;/managed-bean-class&gt;
          &lt;managed-bean-scope&gt;session&lt;/managed-bean-scope&gt;
      &lt;/managed-bean&gt;
  
      &lt;managed-bean&gt;
          &lt;managed-bean-name&gt;ProjectEntityHandlerBean&lt;/managed-bean-name&gt;
          &lt;managed-bean-class&gt;com.example.controller.ProjectEntityHandlerBean&lt;/managed-bean-class&gt;
          &lt;managed-bean-scope&gt;request&lt;/managed-bean-scope&gt;
      &lt;/managed-bean&gt;
  </code></pre>