[jboss-user] [EJB 3.0] - Re: Ejb3.0 jndi lookup problem

Wolfgang Knauf do-not-reply at jboss.com
Thu Sep 9 16:07:28 EDT 2010


Wolfgang Knauf [http://community.jboss.org/people/WolfgangKnauf] created the discussion

"Re: Ejb3.0 jndi lookup problem"

To view the discussion, visit: http://community.jboss.org/message/561188#561188

--------------------------------------------------------------
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 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
[http://community.jboss.org/message/561188#561188]

Start a new discussion in EJB 3.0 at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20100909/c7f52a92/attachment.html 


More information about the jboss-user mailing list