|
| Problem | 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 {} 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*/ } | | Solution | 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. | |
| | | | Product Alias/Synonym | WAS | |
| |
|
Product categories: Software, Application Servers, Distributed Application & Web Servers, WebSphere Application Server, JNDI/Naming Operating system(s): Multi-Platform Software version: 3.5, 4.0, 5.0, 5.1, 6.0 Software edition: Edition Independent Reference #: 1175733 IBM Group: Software Group Modified date: 2004-07-31
(C) Copyright IBM Corporation 2000, 2004. All Rights Reserved.
|