[jboss-user] [JNDI and Naming] - Re: JNDI Lookup fails in JBoss AS 7 [java.naming.CommunicationException]

Kousik Rajendran do-not-reply at jboss.com
Fri Nov 25 08:10:13 EST 2011


Kousik Rajendran [http://community.jboss.org/people/kousikraj] created the discussion

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

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

--------------------------------------------------------------
Hi Abiya,

All you need to do is a very simple arroach. As  http://community.jboss.org/people/wdfink Wolf-Dieter Fink told

> The datasource should only be available inside the server and your code looks like a standalone client.
> 

You should try running only within JBoss AS 7 Environment. Which means, *you cannot try connecting from a standalone Java code.* You should try putting the code inside your web application and test. 

What you can do is, *put this block inside a test servlet and deploy and test i*t. This should work. Note: there is *no need for you to set any property*.

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) {
}

Hope this works for you.

You can check in deatail on how it works in here  http://kousikraj.wordpress.com/2011/11/25/datasource-configuration-setup-for-jboss-as-7-with-example-of-postgresql/ http://kousikraj.wordpress.com/2011/11/25/datasource-configuration-setup-for-jboss-as-7-with-example-of-postgresql/
--------------------------------------------------------------

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

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/20111125/552a0640/attachment.html 


More information about the jboss-user mailing list