在我的托管bean中使用会话ejb时,我得到空指针异常


my  sessionfacade class
         package com.entity;
         import javax.ejb.Stateless;
         import javax.persistence.EntityManager;
         import javax.persistence.PersistenceContext;
         @Stateless
         public class UsersFacade extends AbstractFacade<Users> implements UsersFacadeLocal 
         {
         @PersistenceContext(unitName = "My_communityPU")
         private EntityManager em;
         @Override
         protected EntityManager getEntityManager() {
         return em;
         }
         public UsersFacade() {
         super(Users.class);
         }
         }

my managed bean class
        package com.jsf;
        import com.entity.Users;
        import com.entity.UsersFacadeLocal;
        import javax.inject.Named;
        import javax.enterprise.context.SessionScoped;
        import java.io.Serializable;
        import java.util.List;
        import java.util.Map;
        import javax.annotation.ManagedBean;
        import javax.ejb.EJB;
        import javax.faces.context.ExternalContext;
        import javax.faces.context.FacesContext;
        @Named(value = "loginMB")
        @ManagedBean
        @SessionScoped
        public class LoginMB implements Serializable {
        @EJB
        private UsersFacadeLocal usersFacade;

        protected Users user;
        protected List<Users> lusers;
        protected String username;    
        protected String password;
           public LoginMB() {
        lusers=usersFacade.findAll();

           }
          }

我不知道为什么我的ejb注入到管理bean不工作。当我调用findall()时,我得到空指针异常;方法使用usersFacade我正在netbeans ide与glassfish服务器工作。我只是在JSF中学习jpa,请告诉我哪里做错了

容器仅在实例化托管bean之后注入EJB。使用@PostConstruct注释并在那里使用EJB。

相关内容

  • 没有找到相关文章

最新更新