JBoss Community

JNDI binding and NameNotFoundException

created by David Bailey in JNDI and Naming - View the full discussion

I'm an EJB-newbie, so please bear with me.  I'm running JBoss 5.1.0, and I'm trying to define/deploy/access a stateless session bean.  It's my understanding that JBoss 5.1.0 conforms to EJB 3.0, and so I can do the whole thing with annotations, without the need for a ejb-jar.xml or jboss.xml file.

 

After much Googling, I have tried a number of different ways to do things, most recently the following.  In my bean class, I added a no-args constructor and the following annotation and interface:

 

{code}

@Stateless

public class ScoreComputer implements IScoreComputer

{code}

 

I defined an IScoreComputer class which declares the methods I want to have available, and put the following annotation on it:

 

{code}

@Local

public interface IScoreComputer

{code}

 

In my server code, I try to obtain a reference to my ScoreComputer as follows:

 

{code}

IScoreComputer computer;

InitialContext ejbContext = new InitialContext();

computer = (IScoreComputer)ejbContext.lookup("ScoreComputer/local");

{code}

 

When this code executes, a NameNotFoundException is thrown with the message 'IScoreComputer not bound'.  I know I'm not doing the JNDI binding correctly, because I've looked in the JMX console for JBoss, and no binding is listed containing the string 'Score'.  But try as I might, I am unable to find instructions telling me the correct way to do the binding.

 

I am using the Spring DispatcherServlet as my servlet, and for a while I thought that might be what is causing the problem, and it may well be.  But I replaced that in my web.xml with a simple class which extends HttpServlet, and got the same behavior.  I have also tried injecting my bean using the @EJB annotation, e.g.

 

{code}

@EJB

protected IScoreComputer computer;

{code}

 

but that fails when JBoss attempts to deploy the .ear file, with a message "Resolution should not happen via injection container".

Reply to this message by going to Community

Start a new discussion in JNDI and Naming at Community