JBoss Community

Re: JNDI Lookup fails in JBoss AS 7 [java.naming.CommunicationException]

created by abiya in JNDI and Naming - View the full discussion

Hi Koushik,

 

I was trying to access in the init method of startupservlet

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

public class StartupServlet extends

HttpServlet

{

 

 

// Initializing Logger.

 

 

//private static MLogger s_logger = new MLogger(ServeImagesServlet.class);

 

 

 

/**

* 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/Test");

 

System.out.println("context info in StratupServlet init method...."

+ds);

 

}

 

catch(NamingException e) {

 

 

// TODO

Auto-generated catch block

e.printStackTrace();

}

}

 

And I get the following error,

17:58:09,306 ERROR [stderr] (MSC service thread 1-2) javax.naming.NameNotFoundException: java:jboss/datasources/Test

17:58:09,306 ERROR [stderr] (MSC service thread 1-2)  at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:55)

17:58:09,306 ERROR [stderr] (MSC service thread 1-2)  at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:209)

17:58:09,306 ERROR [stderr] (MSC service thread 1-2)  at javax.naming.InitialContext.lookup(Unknown Source)

17:58:09,306 ERROR [stderr] (MSC service thread 1-2)  at com.common.web.servlet.StartupServlet.init(StartupServlet.java:40)

 

 



 

I get similar error when I try to access from init method of filter as well.

 

I have another basic question,

suppose I invoke a method in utility class from servlet.... will I be able to get the initialcontext using

InitialContext ctx = new InitialContext(); in the utility class?

 

Thanks,

Abiya

 

Reply to this message by going to Community

Start a new discussion in JNDI and Naming at Community