[jboss-user] [JNDI and Naming] - JNDI lookup fails in load-on-startup servlet Jboss as7

abiya do-not-reply at jboss.com
Fri Dec 9 03:34:38 EST 2011


abiya [http://community.jboss.org/people/abiya] created the discussion

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

To view the discussion, visit: http://community.jboss.org/message/640713#640713

--------------------------------------------------------------
Hi,

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>
        <servlet-name>StartupServlet</servlet-name>
        <servlet-class>com.metreo.common.web.servlet.StartupServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

*servlet code*
-----------------
public class StartupServlet extends HttpServlet
{
   /**
    * init method
    */
    public void init(ServletConfig a_config)
throws ServletException
    {
super.init(a_config);
        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);
   callStartupClasses();
  } catch (NamingException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
        
    }
Please help me resolving this issue. I am stuck with this for a long time.

Thanks,
Abiya
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/640713#640713]

Start a new discussion in JNDI and Naming at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20111209/994cdc11/attachment.html 


More information about the jboss-user mailing list