Вопрос

I'm using a stateful session bean to create a shopping basket. I'm having trouble accessing my bean and am getting the following error

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)

I think the problem is in my lookup

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

I'm not exactly sure what to put in the lookup string

My BasketBeanRemote is in a package called ejb.remote and my BasketBean is in ejb.beans in my ejb project

What should go in the lookup? I'm accessing it from my war project.

Это было полезно?

Решение 2

I seem to have found the answer from this post

I needed the @EJB annotation on the servlet:

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

Then lookup in the service method can happen using the name bound by the @EJB annotation:

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

Другие советы

final InitialContext context = new InitialContext();
BasketBeanRemote basket = (BasketBeanRemote)context.lookup("YOUR_PROJECT_NAME/BasketBean/remote");
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top