Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JNDI naming and DI in EJB 3

 
joko mujoko
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The both questions, I try for Session Stateless Bean
 
Shivani Chandna
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Dependency injection is only allowed for Application Client also for servlets and ejb's.

It is not allowed for standalone java client.

Regards.
 
joko mujoko
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 380
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic