| Author |
jndi name in ejb3?
|
Vish Joshi
Greenhorn
Joined: Dec 22, 2010
Posts: 16
|
|
can any one tell me where should i specify the JNDI name in ejb3 or where can i get the default JNDI name?
Many thanks in advance!
|
 |
amit punekar
Ranch Hand
Joined: May 14, 2004
Posts: 488
|
|
Hi,
You usually inject the EJB references in your Web components or another EJBs using annotations. While doing that you can specify the desired JNDI name if you want to look it up in Bean's Environmental Naming Context (ENC). If not provided then there are certain rules as in how the injected EJB will be bound in the JNDI Tree.
Apart from this App. Server specific JNDI name also exists which can be used in annotation attributes. The annotation to look for is @EJB.
Hope this helps,
Amit
|
 |
Vish Joshi
Greenhorn
Joined: Dec 22, 2010
Posts: 16
|
|
|
i am using weblogic 10.3 as the application server!! i went through the jndi tree in weblogic...if i use the name mentioned as 'binding name' in weblogic jndi tree(Environments->Servers->Admin Server->view jndi tree) it gives 'ClassNotFound Exception'..... am i right in locating the default jndi name in the place i mentioned??....if not what is the format of default jndi name in weblogic 10.3?
|
 |
amit punekar
Ranch Hand
Joined: May 14, 2004
Posts: 488
|
|
Hi,
I am not sure abt how do you specify the JNDI name in weblogic 10.3. But you should be able to do that in the weblogic-ejb.xml ( I think this was the filename where we used to configure WLS specific parameters.).
Apart from this we dont know your scenario for accessing the EJB so merely specifying ClassNotFoundException will not help us to resolve the issue. You will need to elaborate more on this.
Regds,
Amit
|
 |
Vish Joshi
Greenhorn
Joined: Dec 22, 2010
Posts: 16
|
|
Bean
package Bean;
import interfaces.EjbBusinessInterface;
import javax.ejb.Stateless;
import javax.ejb.Remote;
@Stateless(mappedName="TestSessionBean")
public class CalculatorBean implements EjbBusinessInterface{
public void add(int x,int y){
System.out.println(x+y) ;
}
}
Business Interafce
package interfaces;
import javax.ejb.Remote;
@Remote
public interface EjbBusinessInterface {
public void add(int x,int y);
}
Client
package Client;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import Bean.CalculatorBean;
public class TestSessionClient {
private static CalculatorBean helloWorld;
public static void main(String[] args)
{
try
{
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL,"t3://192.168.9.168:7001");
Context ctx = new InitialContext(env);
System.out.println("Initial Context created");
helloWorld = (CalculatorBean) ctx.lookup("TestSessionBean");
System.out.println("lookup successful");
System.out.println("Calling EJB method . . .");
helloWorld.add(2,4);
System.out.println("Output will be in Managed server console");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
as i am writing ejb3.0 we do not need the deployment descriptors(ejb-jar.xml,weblogic-ejb-jar.xmal etc.).
in the above files how should i give the jndi name and what is the format of default jndi name for weblogic 10.3?
|
 |
amit punekar
Ranch Hand
Joined: May 14, 2004
Posts: 488
|
|
Hi,
You would need to use weblogic-ejb-jar.xml for providing the JNDI name.
Check this for more information.
regds,
amit
|
 |
Vish Joshi
Greenhorn
Joined: Dec 22, 2010
Posts: 16
|
|
|
weblogic-ejb-jar.xml is used in EJB 2.0 that i know ! but EJB 3.0 is deployment descriptors light (what i hav read from web sites)....in JBOSS and other servers we have a defined format for default jndi names but i am unable to figure it out in weblogic 10.3???
|
 |
amit punekar
Ranch Hand
Joined: May 14, 2004
Posts: 488
|
|
AFAIK you need to fallback on the server specific Deployment Desc. file to specify global JNDI name. You shall not be able to put that in your EJB code. If you do that then your EJB cannot be portable.
|
 |
kp sunil
Greenhorn
Joined: Sep 03, 2008
Posts: 4
|
|
We have been waiting for someone to get a handle on this. Even in WLS 12.1.1 there seems to be some confusion.
From an external client, your EJB can be looked up something like
ctx.lookup("TestSessionBean#interfaces.EjbBusinessInterface");
We are running on WLS and WebSphere and obviously, WebSphere wouldn't like the above. This non-portabilty has always been an issue
|
 |
 |
|
|
subject: jndi name in ejb3?
|
|
|