如何在Servlet中使用@EJB进行资源注入?
平台JBOSS4.2,想在普通的servlet中调用EJB,采用@EJB注入资源,程序如下:
@EJB(name="FrontEquipService/local")
private FrontEquipServiceLocal fe;
测试程序
public void doGet(HttpServletRequest req,HttpServletResponse res){
if(fe==null){
System.out.println(req.getRequestURI());
System.out.println("fe is null");
}else{
List<TabFrontequipment> equips = fe.findAll();
}
}
但是失败,fe总是为null。
同样的方式在JSF的managed-bean里面使用可以。
程序如下:
@EJB(name="FrontEquipService/local")
private FrontEquipServiceLocal fe;
public String save(){
fe.save(frontEquip);
return "saved";
}
其实可以使用lookup方式去做,只是觉得使用annotation更简洁,希望能使用这种方式。
请问那位大虾知道原因,望指教。