【问题标题】:EJB Accessing Stateful Session Bean NameNotFoundExceptionEJB 访问有状态会话 Bean NameNotFoundException
【发布时间】:2012-04-04 12:43:02
【问题描述】:

我正在使用有状态会话 bean 来创建购物篮。我无法访问我的 bean 并收到以下错误

ERROR BasketBean#ejb.remote.BasketBeanRemote -- service jboss.naming.context.java."BasketBean#ejb.remote.BasketBeanRemote"javax.naming.NameNotFoundException: BasketBean#ejb.remote.BasketBeanRemote -- service jboss.naming.context.java."BasketBean#ejb.remote.BasketBeanRemote"
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:87)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:173)
at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:47)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:209)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at controllers.OrderController.processRequest(OrderController.java:104)
at controllers.OrderController.doGet(OrderController.java:157)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:139)
at org.jboss.as.web.NamingValve.invoke(NamingValve.java:57)
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:49)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:154)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:667)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:952)
at java.lang.Thread.run(Thread.java:722)

我认为问题出在我的查找中

final InitialContext context = new InitialContext();
BasketBeanRemote basket = (BasketBeanRemote)context.lookup("BasketBean#ejb.remote.BasketBeanRemote");

我不确定要在查找字符串中放入什么

我的BasketBeanRemote 在一个名为ejb.remote 的包中,而我的BasketBean 在我的ejb 项目中的ejb.beans

查找中应该包含哪些内容?我正在从我的战争项目中访问它。

【问题讨论】:

  • 你的项目叫什么名字?

标签: java hibernate ejb stateful stateful-session-bean


【解决方案1】:
final InitialContext context = new InitialContext();
BasketBeanRemote basket = (BasketBeanRemote)context.lookup("YOUR_PROJECT_NAME/BasketBean/remote");

【讨论】:

    【解决方案2】:

    我好像从this post找到了答案

    我需要 servlet 上的 @EJB 注释:

    @EJB(name="BasketBeanRemote", beanInterface = Bean.class)
    private BasketBeanRemote basketBean;
    

    然后可以使用@EJB注解绑定的名称在服务方法中查找:

    BasketBeanRemote basket = (BasketBeanRemote) new InitialContext().lookup("java:comp/env/BasketBeanRemote");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-12
      • 2013-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-17
      • 1970-01-01
      相关资源
      最近更新 更多