在 Wicket 网页中使用 EJB
当我使用 @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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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.
进一步到前面的答案:由于 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.