在 Wicket 网页中使用 EJB

发布于 2024-09-05 18:49:17 字数 2317 浏览 10 评论 0原文

当我使用 @EJB 注释通过公共 HttpServlet 中的远程接口访问无状态 EJB 时,它工作正常:

public class ListMsgs extends HttpServlet
{
  @EJB
  private Msgs msgsRI;
  ...
  protected void processRequest(...) ...
  {
    List msgs = msgsRI.getAll();
    ...
  }
  ...
}

但是当我在 Wicket WebPage 中尝试相同的操作时,我得到 null 作为 bean 的回报

public class ListM extends WebPage
{
  @EJB
  private Msgs msgsRI;
  ...
  public ListM()
  {
    List msgs = msgsRI.getAll(); // NullPointerException
    ...
  }
  ...
}

:这个“意外的运行时异常”是:

WicketMessage: Can't instantiate page using constructor public testapp.web.ListM()

Root cause:

java.lang.NullPointerException
  at testapp.web.ListM.<init>(ListM.java:22)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
  at org.apache.wicket.session.DefaultPageFactory.createPage(DefaultPageFactory.java:192)
  at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:57)
  at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.newPage(BookmarkablePageRequestTarget.java:298)
  at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.getPage(BookmarkablePageRequestTarget.java:320)
  at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.processEvents(BookmarkablePageRequestTarget.java:234)
  at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
  at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
  at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
  at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
  at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
  at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479)
  at org.apache.wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:138)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
  ....

有带有 bean 的 ejb-module 和带有 servlet 的 web-module,以及部署到 GlassFish v2.1.1 服务器的 wicket 网页(如果这有意义的话)。

我应该怎么做才能通过 wicket 网页中的远程接口使用我的企业 Bean?

When I'm using @EJB annotation to access stateless EJB through remote interface in common HttpServlet, it works OK:

public class ListMsgs extends HttpServlet
{
  @EJB
  private Msgs msgsRI;
  ...
  protected void processRequest(...) ...
  {
    List msgs = msgsRI.getAll();
    ...
  }
  ...
}

But when I'm trying the same thing in Wicket WebPage, I'm getting null in return for bean:

public class ListM extends WebPage
{
  @EJB
  private Msgs msgsRI;
  ...
  public ListM()
  {
    List msgs = msgsRI.getAll(); // NullPointerException
    ...
  }
  ...
}

The several lines of this “Unexpected RuntimeException” are:

WicketMessage: Can't instantiate page using constructor public testapp.web.ListM()

Root cause:

java.lang.NullPointerException
  at testapp.web.ListM.<init>(ListM.java:22)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
  at org.apache.wicket.session.DefaultPageFactory.createPage(DefaultPageFactory.java:192)
  at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:57)
  at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.newPage(BookmarkablePageRequestTarget.java:298)
  at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.getPage(BookmarkablePageRequestTarget.java:320)
  at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.processEvents(BookmarkablePageRequestTarget.java:234)
  at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
  at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
  at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
  at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
  at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
  at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479)
  at org.apache.wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:138)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
  ....

There are ejb-module with bean and web-module with servlet and wicket web page deployed to GlassFish v2.1.1 server (if this makes any sense).

What should I do to use my enterprise bean through remote interface in wicket webpage?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

强辩 2024-09-12 18:49:17

Java EE 集成项目可以在这里找到: http://wicketstuff.org/ confluence/display/STUFFWIKI/wicket-contrib-javaee

由于 Wicket 组件实例化不受 DI 容器管理,因此它必须提供代理注入机制。有一个基于 org.apache.wicket.injection.Injector 类的标准方法来实现这一点。

The Java EE integration project can be found here: http://wicketstuff.org/confluence/display/STUFFWIKI/wicket-contrib-javaee

As Wicket component instantiation is unmanaged by the DI container, it must provide a proxy injection mechanism. There is a standard way of implementing this, based around the org.apache.wicket.injection.Injector class.

帅哥哥的热头脑 2024-09-12 18:49:17

进一步到前面的答案:由于 ejb3 风格,在第一步中声明 @Stateless 注释中的 name 元素是更好的方法,而不是在 如何使用 ejb 注释

Further to previous answer: due to ejb3 style it is better way to declare name element within @Stateless annotation at 1st step instead of the whole 3rd step in using ejb annotation how to.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文