1 Reply Latest reply on Aug 4, 2006 5:10 AM by jaikiran pai

    JNDI name not bound when servlet initializes

    Jon French Newbie

      JBOSS 4.0.3.SP1

      I have a servlet which on initialization (i.e. a call to its init(ServletContext) method) attempts to do a JNDI lookup to a datasource defined in a *-ds.xml file in my deploy directory. This works just fine as long as the servlet is not loaded when the context is loaded (i.e. the servlet's <load-on-startup> element is not defined).

      However, when I set <load-on-startup> to a positive integer, the servlet initialization errors with a javax.naming.NameNotFoundException when trying to lookup the JNDI datasource name. To fix the error, all I have to do is touch the application's jboss-service.xml file to re-deploy the application. Presumably since the JNDI datasource is now correctly bound, the servlet initializes without difficulty.

      Thus it seems as though my problem is that my sar (and thus the servlet context) is being deployed by JBoss before the Datasource is bound to JNDI. Is there a way in which to change this deployment ordering? I've tried many different hacks to try to get JBoss to bind the JNDI name before my context is loaded, all with no luck.

      Can anyone help!?