Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to modify the JNDI names?

 
K Kiran Kumar
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using Eclipse+WAS 7 to develop my application. I have an EAR, which has a web application module and an EJB module.
I am able to access my EJB methods using the below client code. This code is from my web application.

My Client to access EJB methods:


Local interface:

Remote interface:

EJB Bean:


I learned that I am accessing the default JNDI name of the EJB.
Could someone please let me know how/where I can customize the JNDI names to access the EJB bean methods so that I can access the bean methods using
ctx.lookup("xx/yyl"); instead of ctx.lookup("ejblocal:a.b.ie.StateLessBeanLocal");

Regards,
Kiran.
 
Kevin Sheng
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can put the default name ejblocal:a.b.ie.StateLessBeanLocal to a property file and refer the service as a shorter name like xx.yyl.

In case your ejb changes, just update the property file without changing the code.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this for your stateless bean:



You should then be able to lookup your bean using "foo".

Note, a downside to this is that it makes your code less portable.

http://docs.oracle.com/javaee/6/api/javax/ejb/Stateless.html
 
K Kiran Kumar
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kevin - Thank you for the response. However, I am looking for the name change as James Suggested.

James - Thanks a lot for your response. I tried out your suggestion. However, I get NameNotFoundException.
I used
StateLessBeanLocal local = (StateLessBeanLocal) ctx.lookup("foo"); in my client code and
@Stateless(name = "foo", mappedName="foo") in my Bean class

Please let me know if I am missing anything here.

Regards,
Kiran.

 
K Kiran Kumar
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I found the solution. Search for the file ibm-ejb-jar-bnd.xml (should be in ejbModule/META-INF/). Keep an entry in the file.
Example:
<session name="xxxServiceClass" simple-binding-name="ejb/abcd">
<resource-ref name="datasources" binding-name="datasource JNDI name"/> <! This is not mandatory-->
</session>

Regards,
Kiran.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic