1 Reply Latest reply: Dec 10, 2011 7:18 AM by Wolf-Dieter Fink RSS

    JNDI lookup fails in load-on-startup servlet Jboss as7

    abiya Newbie



      I am able to perform JNDI lookup using the following code in any of my servlet as follows,


      DataSource ds = null;
      Context ctx = null;
      try {

              String strDSName = "java:jboss/datasources/Test";
              ctx = new InitialContext();
              ds = (javax.sql.DataSource) ctx.lookup(strDSName);

      } catch (Exception e) {


      But the same code fails if it is invoked from init() method of load-on-startup servlet. My datasource is bound well before this.My console says,

      13:26:06,881 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) Bound data source [java:jboss/datasources/weblogic.jdbc.jts.demopool]


      web.xml entry




      servlet code


      public class StartupServlet extends HttpServlet

          * init method
          public void init(ServletConfig a_config)
      throws ServletException
              System.out.println("StartupServlet.init() called.");

           try {
         InitialContext ctx = new InitialContext();
         DataSource ds = (javax.sql.DataSource) ctx.lookup("java:jboss/datasources/weblogic.jdbc.jts.demopool");

         System.out.println("context info in StratupServlet init method...."+ds);
        } catch (NamingException e) {
         // TODO Auto-generated catch block

      Please help me resolving this issue. I am stuck with this for a long time.