When An Application Is Started a NameNotFoundException Occurs
 Technote (troubleshooting)
 
Problem(Abstract)
An application throws a NameNotFoundException during application startup time. A dumpNameSpace after the application starts shows that the name is in the name space, and after checking the code the lookup is performed on the correct server with the correct port number.
 
Cause
The initial context and lookup are performed in a static code block.

Example:

static {

try {
initialize();
} catch (Exception e) {
System.out.println("Caught Exception: " + e.toString());
e.printStackTrace();
}
}

private static void initialize() throws Exception {
Hashtable props = new Hashtable();
props.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
props.put(Context.PROVIDER_URL, "corbaloc:iiop:localhost:2809");
InitialContext ctx = new InitialContext(props);
Object home = ctx.lookup("cell/nodes/MYNODE/servers/server1/MyEJB");
/* do something with the object after this point*/
}
 
Resolving the problem
Move the code out of the static block. This code cannot be run in a static block, because the name won't be bound into the name space before the look-up is performed. The static code block throws the timing off.
Any invocation of J2EE™ APIs in code being considered for a static code block should instead be placed in the bean's ejbCreate() method, or if the code is not in an EJB™, in an explicit initialize() method (or other name as desired) that is invoked from within an EJB's ejbCreate() method. In the case of a servlet, the servlet's init() method should be used for this purpose.
 
 
Cross Reference information
Segment Product Component Platform Version Edition
Application Servers Runtimes for Java Technology Java SDK
 
 


Document Information


Product categories: Software > Application Servers > Distributed Application & Web Servers > WebSphere Application Server > JNDI/Naming
Operating system(s): Windows
Software version: 6.0
Software edition:
Reference #: 1175733
IBM Group: Software Group
Modified date: Jul 18, 2005