0
我對EJB沒有太多的瞭解,請執行我,如果我問一些明顯的問題。這是我的EJB:EJB'查找失敗的'java:comp/env/ejb/CategoryFacade'
@Stateless
public class CategoryFacade extends AbstractFacade<Category> {
@PersistenceContext(unitName = "AffableBeanPU")
private EntityManager em;
protected EntityManager getEntityManager() {
return em;
}
public CategoryFacade() {
super(Category.class);
}
}
我有一個叫AffableBeanService
類,基本上它是一個REST服務類。在此我想調用EJB如下:
@GET
@Path("/categories/{categoryId}")
public String getInfo(@PathParam("categoryId") String categoryId) {
//Note I have removed try, catch etc to save the space
CategoryFacade categoryFacade; //This is a class, not a interface
InitialContext ic = new InitialContext();
categoryFacade = (CategoryFacade)ic.lookup("java:comp/env/ejb/CategoryFacade");
}
在運行時我得到異常作爲javax.naming.NamingException: Lookup failed for 'java:/env/ejb/CategoryFacade' in SerialContext[myEnv
。我不確定,我在這裏錯過了什麼。誰能幫幫我嗎?
而且我想是這樣的:
@EJB
CategoryFacade categoryFacade;
但同樣EJB注入不會發生,我得到NullPointerException異常。我假設我缺少一些配置,或者我不確定我是否以正確的方式調用EJB。任何人都可以引導我?