[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


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.


Reply to this message by going to Community

Start a new discussion in JNDI and Naming at Community

-------------- 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