I'm trying to use JNDI to obtain a new Stateful Session Bean in a servlet (as a local variable). My doGet()
method has the following:
Bean bean = (Bean) new InitialContext().lookup("beanName");
I've tried including java:comp/env
but all of my attempts have led to naming exceptions.
I'm attempting to bind the bean in the @Stateful
annotation, using various guesses like @Stateful(name="beanName")
and @Stateful(mappedName="beanName")
What I needed was to use the
@EJB
annotation on the servlet at the class level, as follows:Then lookup in the service method can happen using the name bound by the
@EJB
annotation:There is no need for anything in the Bean class itself, other than the plain
@Stateful
annotation.