当我尝试在控制器中注入 EJB 时出现错误。
Caused by: com.sun.faces.spi.InjectionProviderException: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Remote ejb-ref name=controllers.ScheduleController/calendrierDao,Remote 3.x interface =dao.CalendrierDao,ejb-link=null,lookup=,mappedName=,jndi-name=dao.CalendrierDao,refType=Session into class controllers.
不知道是豆子本身还是..
@EJB
private ActionDao actionDao;
@EJB
private CalendrierDao calendrierDao;
第一个注入正确,我可以使用它。但是第二个给了我上述错误。
失败的ejb代码:
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.LocalBean;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.NamedQueries;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceUnit;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import javax.servlet.http.HttpSession;
import entities.Action;
import entities.TCalendrier;
import entities.Titre;
@SessionScoped
@ManagedBean
public class CalendrierDao implements ICalendrierDao, Serializable {
/**
*
*/
private static final long serialVersionUID = -270548339881483437L;
// private static final String SELECT_ALL_CALENDAR =
// "SELECT cal FROM t_calendriers cal where c.utilCreation =: utilCreation";
private static final String SELECT_TITLE_NAME = "SELECT t.titreEnClair FROM t_titres t
private FacesMessage message;
private List<TCalendrier> allCalendar;
@PersistenceUnit
private EntityManagerFactory emf;
@PersistenceContext(unitName = "GA2010-ejbPU-dev")
private EntityManager em;
public CalendrierDao() {
super();
}
@PostConstruct
public void init() {
HttpSession sess = (HttpSession) FacesContext.getCurrentInstance()
.getExternalContext().getSession(true);
String codeUser = (String) sess.getAttribute("codeUser");
try {
TypedQuery<TCalendrier> requete = em.createNamedQuery(
"typeCalendrier.findAll", TCalendrier.class);
// TypedQuery<TCalendrier> requete =
// em.createQuery(SELECT_ALL_CALENDAR, TCalendrier.class);
requete.setParameter("utilCreation", codeUser);
allCalendar = requete.getResultList();
} catch (Exception e) {
this.message = new FacesMessage(e.getMessage());
FacesContext.getCurrentInstance().addMessage(null, message);
}
}
public List<TCalendrier> getAllCalendar() {
return allCalendar;
}
public String getTitleName(Integer refTitre_p) {
String titre = null;
try {
Query requete = em.createQuery(SELECT_TITLE_NAME);
requete.setParameter("refTitre", refTitre_p);
titre = (String) requete.getSingleResult();
} catch (NoResultException nre) {
nre.printStackTrace();
}
return titre;
}
}