[jboss-user] [JNDI and Naming] - Re: JNDI Lookup fails in JBoss AS 7 [java.naming.CommunicationException]
abiya
do-not-reply at jboss.com
Tue Nov 29 07:41:29 EST 2011
abiya [http://community.jboss.org/people/abiya] created the discussion
"Re: JNDI Lookup fails in JBoss AS 7 [java.naming.CommunicationException]"
To view the discussion, visit: http://community.jboss.org/message/638860#638860
--------------------------------------------------------------
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
[http://community.jboss.org/message/638860#638860]
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/20111129/7fa33ce4/attachment-0001.html
More information about the jboss-user
mailing list