JBoss Community

Re: Ejb3.0 jndi lookup problem

created by Wolfgang Knauf in EJB 3.0 - View the full discussion

Hi,

 

it is your decision whether you want to use injection (using the "@EJB" annotation) or whether you want to perform a JNDI lookup.

 

A file "jboss.xml" is not needed in both ways.

 

If you want to use injection: import the sample attached to the wiki document ("Stateless.ear") into Eclipse. Now you will find a project consisting of three modules. Take a look at the code and the configuration, and then try to run my sample as described. You might take a look at this page: http://www.cs.hs-rm.de/~knauf/KomponentenArchitekturen2008/stateless/index.html#appclientstart  - it is german, but there are some screenshots which will show you some important settings.

 

If you don't want to inject, but perform a JNDI lookup, you need this code snippet:

 

 

Properties props = new Properties();
        props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
        props.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming.client");
        props.setProperty(Context.PROVIDER_URL, "jnp://localhost:1099");
       
        InitialContext initialContext = new InitialContext(props);
        StatelessSessionExampleRemote sessionBeanBean = (StatelessSessionExampleRemote) initialContext.lookup("java:InsertYourBeanNameHere");

 

 

This should do it. Instead of passing Properties to the "InitialContext", you could use a "jndi.properties" file, as Wolf-Dieter suggests.

The JNDI name of the bean defaults to "insertearname/insertbeanclass/remote".

 

Hope this helps

 

Wolfgang

Reply to this message by going to Community

Start a new discussion in EJB 3.0 at Community