0
我的高级目标是使用由NetBeans生成的JPA代码,通过使用在我的servlet中创建“来自数据库的REST风格的Web服务”向导。如何将无状态会话bean注入到servlet中?
更确切地说,我想直接从servlet访问Facade,以避免在客户端使用JavaScript加载一些数据。
我的门面的相关部分看起来是这样的:
@Stateless
@Path("wgm.rest.balanceview")
public class BalanceViewFacadeREST extends AbstractFacade<BalanceView> {
@PersistenceContext(unitName = "WGManagerPU")
private EntityManager em;
@GET
@Override
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public List<BalanceView> findAll() {
return super.findAll();
}
}
现在我试过如下:
@WebServlet(name = "BalanceServlet", urlPatterns = "/balance/*")
public class BalanceServlet extends HttpServlet {
@Inject
private BalanceViewFacadeREST balanceFacade;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
List<BalanceView> balances = balanceFacade.findAll();
// ...
}
}
但是,在部署到GlassFish时,我得到以下异常:
java.lang.RuntimeException: Unable to load the EJB module. DeploymentContext does not contain any EJB. Check the archive to ensure correct packaging for /home/severin/Projects/WGManager/build/web.
If you use EJB component annotations to define the EJB, and an ejb or web deployment descriptor is also used, please make sure that the deployment descriptor references a Java EE 5 or higher version schema, and that the metadata-complete attribute is not set to true, so the component annotations can be processed as expected
这听起来像是我注射器无法找到BalanceViewFacadeREST。我错过了什么?
谢谢!不幸的是,我对EJB真的很陌生,所以我不知道为什么我们需要@LocalBean,但我想我将不得不深入探讨这个主题。 无论如何,这解决了上述问题,但现在我得到一个严重的日志消息: “Severe:Class [Lwgm/rest/service/BalanceViewFacadeREST;] not found。Error loading while [class wgm.servlets.BalanceServlet]”and I为我的所有路径获取404(也是与/无关的路径)。这可能是相关的还是这是另一个问题?顺便说一句,即时通讯使用Glassfish版本4.1.1。 – Severin
因为我完全清理并重建了应用程序并删除了Glassfish中的'generated'和'osgi-chache'目录(只是可以肯定),所以我不再收到严重的日志消息。 NetBeans部署到Glassfish似乎是一个问题。当我手动将War-archive复制到Glassfish autodeploy文件夹时,它工作正常。但我想我会为这个问题提出一个新的问题。 – Severin