File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes JNDI naming and DI in EJB 3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "JNDI naming and DI in EJB 3" Watch "JNDI naming and DI in EJB 3" New topic
Author

JNDI naming and DI in EJB 3

joko mujoko
Greenhorn

Joined: Dec 28, 2006
Posts: 8
Dear All,

I really new to EJB 3. I try some example code of EJB 3. I found some problem

1. Aboout standart default JNDI naming in, Its look different for each app.server in. Is not it?
in Jboss for session
context.lookup("shortnameClass/remote");
in sjas for session
context.lookup("fullnameClass/remote");
which one will be use as srandart ans also being asked in SCBCD 5?

2. I try this snippet
package ejb3inaction.example;

import javax.ejb.EJB;

public class HelloUserClient {
@EJB
private static HelloUser helloUser;

public static void main(String[] args) {


helloUser.sayHello("Curious George");
System.out.println("Invoked EJB successfully .. see server console for output");
}
}


and i got null pointer Exception. Is it because I used Dependency Injection in stand alone aplication in @EJB to inject the bean?

thank's before for all rancher

Mujoko
Never Ending Improvement
joko mujoko
Greenhorn

Joined: Dec 28, 2006
Posts: 8
The both questions, I try for Session Stateless Bean
Shivani Chandna
Ranch Hand

Joined: Sep 18, 2004
Posts: 380
Yes Dependency injection is only allowed for Application Client also for servlets and ejb's.

It is not allowed for standalone java client.

Regards.


/** Code speaks louder than words */
joko mujoko
Greenhorn

Joined: Dec 28, 2006
Posts: 8
Thank You Shivani,

Its clear now about null pointer in stand alone client.
How about standart naming in JNDI for EJB 3?
Shivani Chandna
Ranch Hand

Joined: Sep 18, 2004
Posts: 380
Hello Joko,

Well I have used jboss and it uses class<shortname>/remote as you rightly mentioned. In in Head First SCBCD they mention a look with complete naming context i.e java:comp/env/ejb/<MyEJBName>, where ejb/MyEJBName is specified name for ejb ref in the DD.

In my test jboss application I could look up using the following:


For each application server, there are different provisions in addition for lookups. Like jboss has @RemoteBinding to specify the jndi name for bean lookup etc.

Regards,
Shivani
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JNDI naming and DI in EJB 3