Refresh Your Java - Before Java Interview
We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....
You get this Exception during the JNDI look up, if
the Bean or the Resource is not available with the
given
JNDI name , this will be thrown.
In order to fix do the following.
i) Firstly review the way you do JNDI look
up is incline with your App Server Specification.
J2ee Server (sun) :
Context
subcontext = (Context)
ic.lookup("java:comp/env");
DataSource
dataSource = (DataSource)
subcontext.lookup("jdbc/default-datasource");
Weblogic
:
Context ctx = null;
Hashtable ht =
new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,
"t3://localhost:7001");
try {
ctx = new InitialContext(ht);
ctx.bind("my_object", MyObect);
ServiceBean bean =
(ServiceBean)ctx.lookup("ejb.serviceBean");
}
catch (NamingException e) {
// a failure
occurred
}
WebSphere:
Properties p
= new Properties();
p.put("org.omg.CORBA.ORBClass","com.sun.CORBA.iiop.ORB");
p.setProperty(
javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory"
);
p.setProperty(
"java.naming.provider.url",
"iiop://HOSTNAME:PORT" );
String
connectionfactoryjndi="jms/testQCF";
Context jndiContext = new InitialContext();
jndiContext
= new InitialContext( p );
ii) Secondly please restart your Application Server like Welogic or
WebSphere beacuse unless
you restart some of
the App Services will not BIND the resource .
iii) Then take a look at JNDI
tree in App Server if it has one built in if not print the
resource names as shown below and search for your
Resource.
Print JNDI Tree
:
Context ic = new
InitialContext(properties);
context.list(ct);
Browse JNDI Tree:
http://servername:port_number/jndiTree/index.html
This Portal is intended to put all Java/J2ee related topics at one single place for quick referance, not only Technical , but also the Project Management Related thing such as Development Process methodoogies build process, unit testing etc.,
This Portal has More than 500 Java Interview Questions (also could be Considered as Quick Notes) very neatly separated topic by topic with simple diagrams which makes you easily understandable. Importantly these are from our Realtime expericance.