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 注入 mangedbean 不起作用。调用 findall(); 时出现空指针异常;使用 usersFacade 的方法我正在使用 glassfish 服务器处理 netbeans ide。我只是在 jsf 中学习 jpa 请让我知道我在哪里做错了