title: managed bean field is null when invoke bean method primefaces jsf
body: <p>I am developing a primefaces - spring framework application but i have a big problem with my beans</p>
  
  <p>i'm using spring annotations in java code to discover my beans, services, or component</p>
  
  <p>but the problem is when i start jboss 7.1 AS and the beans are created i can see that my bean ListUsersBean</p>
  
  <p>is created succesfully and the autowired setters are set successfully, but after when i try to invoke a test() method </p>
  
  <p>from jsf page  the autowired attributes are null.</p>
  
  <p>I dont know what is happening</p>
  
  <p>thanks a lot if anyone may help me</p>
  
  <p>i'm using </p>
  
  <p>spring-framework 3.2.2
  JBOSS AS 7.1
  primefaces 3.5</p>
  
  <p>this is my bean</p>
  
  <pre><code>package edu.unbosque.beans;
  
  import java.io.Serializable;
  import java.util.List;
  
  import javax.faces.bean.ManagedBean;
  import javax.faces.bean.SessionScoped;
  import javax.faces.bean.ManagedProperty;
  
  import edu.unbosque.model.User;
  import edu.unbosque.services.IUserService;
  import edu.unbosque.services.TestService;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Qualifier;
  import org.springframework.stereotype.Component;
  
  
  @Component
  @ManagedBean
  @SessionScoped
  public class ListUsersBean implements Serializable{
      /**
       * Acceso A Datos De Usuario
       */
      private IUserService userService;
  
  
      private TestService testService;
      /**
       * Listado De Usuarios
       */
      private List&lt;User&gt; usersList;
      /**
       * Usuario Seleccionado
       */
      private User selectedUser;
      /**
       * Carga Los Usuarios
       */
      private void populateUsers(){       
          this.usersList = this.userService.getUsers();
      }
      public IUserService getUserService() {
          return userService;
      }
  
      @Autowired(required = true)
      @Qualifier("userServiceImpl")
      public void setUserService(IUserService userService) {
          this.userService = userService;
      }
      public List&lt;User&gt; getUsersList() {
          return usersList;
      }
      public void setUsersList(List&lt;User&gt; usersList) {
          this.usersList = usersList;
      }
      public User getSelectedUser() {
          return selectedUser;
      }
      public void setSelectedUser(User selectedUser) {
          this.selectedUser = selectedUser;
      }   
  
      public TestService getTestService() {
          return testService;
      }
  
      @Autowired
      public void setTestService(TestService testService) {
          this.testService = testService;
      }
  
      public void test(){ 
  
          this.testService = this.getTestService();
  
          int i = 1;
          i = i + 2;
      }
  }
  </code></pre>
  
  <p>this is my service </p>
  
  <pre><code>package edu.unbosque.services;
  
  import java.util.List;
  
  import javax.faces.bean.ManagedProperty;
  
  import org.hibernate.Query;
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.Transaction;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.security.core.userdetails.UserDetails;
  import org.springframework.security.core.userdetails.UsernameNotFoundException;
  import org.springframework.stereotype.Service;
  
  
  import edu.unbosque.*;
  import edu.unbosque.dao.UserDao;
  import edu.unbosque.model.User;
  import javax.inject.Named;
  
  @Named("userServiceImpl")
  public class UserServiceImpl implements IUserService{
  
      @Autowired
      private UserDao userDao; 
  
      public UserDao getUserDao() {
          return userDao;
      }
  
      public void setUserDao(UserDao userDao) {
          this.userDao = userDao;
      }
  
      @Override
      public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {                       
          return (UserDetails) userDao.getUserByUserName(username);
      }
  
      @Override
      public List&lt;User&gt; getUsers() {
          return getUserDao().getUsers();
      }      
  }
  </code></pre>
  
  <p>config files </p>
  
  <p>faces-config.xml</p>
  
  <p>*</p>
  
  <pre><code>&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;el-resolver&gt;org.springframework.web.jsf.el.SpringBeanFacesELResolver&lt;/el-resolver&gt;
      &lt;/application&gt;
  
      &lt;lifecycle&gt;
          &lt;phase-listener&gt;edu.unbosque.listeners.LoginPhaseListener&lt;/phase-listener&gt;
      &lt;/lifecycle&gt;
  &lt;/faces-config&gt;
  </code></pre>
  
  <p>*</p>
  
  <p>spring-database.xml</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:context="http://www.springframework.org/schema/context"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"        
         xmlns:mvc="http://www.springframework.org/schema/mvc"
         xmlns:p="http://www.springframework.org/schema/p"
         xmlns:tx="http://www.springframework.org/schema/tx"
         xsi:schemaLocation="
          http://www.springframework.org/schema/beans    
          http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-3.2.xsd
          http://www.springframework.org/schema/tx
          http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"&gt;
  
         &lt;context:annotation-config /&gt;
         &lt;context:component-scan base-package="edu.unbosque.model" /&gt;
         &lt;context:component-scan base-package="edu.unbosque.dao" /&gt;
         &lt;context:component-scan base-package="edu.unbosque.services" /&gt;
         &lt;context:component-scan base-package="edu.unbosque.beans" /&gt;    
  
         &lt;context:property-placeholder location="classpath:jdbc.properties" /&gt;
         &lt;tx:annotation-driven transaction-manager="hibernateTransactionManager" /&gt;
         &lt;bean id="hibernateTransactionManager"
                class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
                &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
         &lt;/bean&gt;
         &lt;bean id="dataSource"
                class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
                &lt;property name="driverClassName" value="${database.driver}" /&gt;
                &lt;property name="url" value="${database.url}" /&gt;
                &lt;property name="username" value="${database.user}" /&gt;
                &lt;property name="password" value="${database.password}" /&gt;
         &lt;/bean&gt;
  
         &lt;bean id="sessionFactory"
                class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
                &lt;property name="dataSource" ref="dataSource" /&gt;
                &lt;property name="annotatedClasses"&gt;
                       &lt;list&gt;
                             &lt;value&gt;edu.unbosque.model.User&lt;/value&gt;
                             &lt;value&gt;edu.unbosque.model.Authority&lt;/value&gt;                           
                       &lt;/list&gt;
                &lt;/property&gt;
                 &lt;property name="hibernateProperties"&gt;
                       &lt;props&gt;
                             &lt;prop key="hibernate.dialect"&gt;${hibernate.dialect}&lt;/prop&gt;
                             &lt;prop key="hibernate.show_sql"&gt;${hibernate.show_sql}&lt;/prop&gt;
                              &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt;
  
                       &lt;/props&gt;
                &lt;/property&gt;         
          &lt;/bean&gt;
  
         &lt;bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/&gt;             
  &lt;/beans&gt;
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>&lt;web-app id="WebApp_ID" version="2.4"
      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"&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.request.RequestContextListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;           
              /WEB-INF/spring-security.xml,
              /WEB-INF/spring-database.xml
          &lt;/param-value&gt;
      &lt;/context-param&gt;
  
  
      &lt;display-name&gt;Semilleros Universidad El Bosque&lt;/display-name&gt;
  
      &lt;!-- Change to "Production" when you are ready to deploy --&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;!-- Welcome page --&gt;
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  
      &lt;!-- JSF mapping --&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;!-- Map these files with JSF --&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;*.jsf&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;*.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;context-param&gt;
          &lt;param-name&gt;primefaces.THEME&lt;/param-name&gt;
          &lt;param-value&gt;bootstrap&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;!-- Spring Security --&gt;
      &lt;filter&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
      &lt;/filter&gt;
  
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
          &lt;dispatcher&gt;FORWARD&lt;/dispatcher&gt;
          &lt;dispatcher&gt;REQUEST&lt;/dispatcher&gt;
      &lt;/filter-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/GM5jF.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/HxJ1A.png" alt="enter image description here"></p>