-
1. Re: javax.naming.NameNotFoundException: jdbc not bound
peterj May 20, 2009 10:30 AM (in response to dickson1888)Does this help: http://www.jboss.org/community/wiki/HowDoICreateAResourceRef
If not, please post the following:
* oracle-ds.xml file (mainly interested in the jndi-name entry)
* web.xml file (mainly interested in the resource-ref entry for the database)
* jboss-web.xml (mainly interested in the resource-ref entry for the database)
* code that does the lookup -
2. Re: javax.naming.NameNotFoundException: jdbc not bound
dickson1888 May 21, 2009 3:37 AM (in response to dickson1888)Thanks for Peter's help.
Refer to the "Setup a Oracle Datasource" article , http://www.jboss.org/community/wiki/SetUpAOracleDatasource,
Refer to the "DataSource configuration" article ,
http://www.jboss.org/community/wiki/ConfigDataSources
Both of these 2 article do not mention that it needs to config "web.xml" and jboss-web.xml".
About the link to "How do I create a resource-ref?" article, it also does not show how to config for these 2 xml file.
So stranger, there is no correct document or article to completely guide the end user to setup the data source for a web application to use.
Dear JBoss,
Please create a better documentation for using JBoss AS so that any end user won't need to search around to find the usage/method/solution of using JBoss AS.
Thanks a lot. -
3. Re: javax.naming.NameNotFoundException: jdbc not bound
peterj May 21, 2009 10:46 AM (in response to dickson1888)I'm sorry, I didn't look carefully enough at the config files presented in the wiki entry that I referred you to, and did not realize that the information was not relevant for a web app. Here is an example (usually the basic datasource name is the same in all the files, but I used different names so that you can see which names need to be the same):
*-ds.xml excerpt:<jndi-name>jdbc/SomeDS</jndi-name>
web.xml excerpt:<resource-ref> <res-ref-name>jdbc/TheDS</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref>
jboss-web.xml:<jboss-web> <resource-ref> <res-ref-name>jdbc/TheDS</res-ref-name> <jndi-name>java:jdbc/SomeDS</jndi-name> </resource-ref> </jboss-web>
datasource lookup in servlet:InitialContext ctx = new InitialContext(); DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/TheDS");
-
4. Re: javax.naming.NameNotFoundException: jdbc not bound
bwalker55 Oct 7, 2009 12:53 PM (in response to dickson1888)I've been referred here from my own similar query: http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4259203#4259203
From what I can gather from this thread, a web.xml and jboss-web.xml must exist in the WEB-INF directory of every application that wants to access the globally defined datasource: *.ds.xml.
It would appear the purpose of the these two files is to map a Java EE Environment Naming Context (enc) 'local' entry (ie java:/comp/env/jdbc/MyDataSource) to a jBossNS 'global' naming entry (ie java:/MyDataSource). Have I got this right?
Now, is there a way to globally define this mapping for all jBoss web applications in a similar fashion that the *-ds.xml datasource is globally defined? I would like to deliver an application that does not have jBoss specific configuration entries in the web.xml and does not need a jboss-web.xml file.
I know there are applications (I've installed at least one) that work with jBoss that only need the *-ds.xml deployed. What's the trick?
Thanks, Bob. -
5. Re: javax.naming.NameNotFoundException: jdbc not bound
peterj Oct 7, 2009 1:08 PM (in response to dickson1888)It would appear the purpose of the these two files is to map a Java EE Environment Naming Context (enc) 'local' entry (ie java:/comp/env/jdbc/MyDataSource) to a jBossNS 'global' naming entry (ie java:/MyDataSource). Have I got this right?
Yes.Now, is there a way to globally define this mapping for all jBoss web applications in a similar fashion that the *-ds.xml datasource is globally defined? I would like to deliver an application that does not have jBoss specific configuration entries in the web.xml and does not need a jboss-web.xml file.
No. The ENC is application-specific. In fact, each web app gets its own ENC. You can verify this by using JNDIView (in the jmx console). And each app can see only its own ENC.I know there are applications (I've installed at least one) that work with jBoss that only need the *-ds.xml deployed. What's the trick?
You can have the app directly look up "java:/MyDatasource" instead of using "jdbc/MyDatasource". In that case you do not need any of the web.xml or jboss-web.xml entries. -
6. Re: javax.naming.NameNotFoundException: jdbc not bound
bwalker55 Oct 7, 2009 1:42 PM (in response to dickson1888)You can have the app directly look up "java:/MyDatasource" instead of using "jdbc/MyDatasource". In that case you do not need any of the web.xml or jboss-web.xml entries.
I'd already made that change in our source code as a temporary fix. Guess we'll keep it :-)
Thanks for the quick response.
Bob. -
7. Re: javax.naming.NameNotFoundException: jdbc not bound
samalexander10 Jun 1, 2011 8:31 PM (in response to peterj)Hi Peter,
For this:
jboss-web.xml:
<jboss-web>
<resource-ref>
<res-ref-name>jdbc/TheDS</res-ref-name>
<jndi-name>java:jdbc/SomeDS</jndi-name>
</resource-ref>
</jboss-web>
why wouldn't it be:
jboss-web.xml:
<jboss-web>
<resource-ref>
<res-ref-name>
java:comp/env/
jdbc/TheDS</res-ref-name><jndi-name>java:jdbc/SomeDS</jndi-name>
</resource-ref>
</jboss-web>
How does JBoss know to include
java:comp/env/
in the <res-ref-name> if we just put<res-ref-name>jdbc/TheDS</res-ref-name>
-
8. Re: javax.naming.NameNotFoundException: jdbc not bound
peterj Jun 2, 2011 10:05 AM (in response to samalexander10)Because the ENC is assumed since it is in the context of a web app.
-
9. Re: javax.naming.NameNotFoundException: jdbc not bound
samalexander10 Jun 2, 2011 11:13 AM (in response to peterj)Thanks for the quick response Peter!
For a follow up...
Say that I have a framework (like Spring) that has another layer of code where you can have a "datasource" bean that essentially holds the jndi name (eg. jdbc/TheDS) in a spring context xml file. Spring converts the jndi name to java:comp/env/jdbc/TheDS in the background.
Would JBoss still see be able to see that the code is using java:comp/env in front of TheDS jndi name even though the java:comp/env is appended in front of TheDS jndi name only at runtime by Spring used in a class (org.springframework.jdbc.core.JdbcTemplate) found inside a Spring jar.
In other words using a framework like Spring that manages datasources at the application layer can we still successfully map to JBoss's -ds.xml jndi name java:jdbc/SomeDS.
Another answer to a question I would love to know is if this mapping technique can be done only for WARs in JBoss? How about if I just have a bunch of EJBs and/or jars packaged in an EAR file. Is there an EAR equivalent technique to map the jndi names to the JBoss' -ds.xml jndi name.
Again, I appreciate your help!
-
10. Re: javax.naming.NameNotFoundException: jdbc not bound
peterj Jun 2, 2011 12:03 PM (in response to samalexander10)I don't use Spring (or rather it has been ages since I did anything with Spring) so I could not comment on that.
As far a EJBs go, I always use the straight JNDI name (
java:jdbc/SomeDS
in the example). There is no need to translate ENC into the JNDI name. -
11. Re: javax.naming.NameNotFoundException: jdbc not bound
samalexander10 Jun 2, 2011 12:09 PM (in response to peterj)Perfect. Thanks!
-
12. Re: javax.naming.NameNotFoundException: jdbc not bound
rzvikas Feb 23, 2012 4:51 PM (in response to samalexander10)Adding this to the *-ds.xml , worked for me......It make your datasource available to the Global JNDI namespace in JBOSS
<use-java-context>false</use-java-context>
-
13. Re: javax.naming.NameNotFoundException: jdbc not bound
madhuripotdar Jun 27, 2012 2:43 AM (in response to peterj)I have made all the necessary configurations to lookup a DB2 datasource on JBboss from a portlet. I am able to lookup that datasource from one portlet successfully.
However using same configurtions from another portlet, the lookup fails and gives following error -
java.lang.RuntimeException: javax.naming.NameNotFoundException: jdbc not bound
As it is able to looup the datasource from first portlet, it makes me think that the datasource is configured correctly on server. It is something very obvious missing in other portlet which I am not able to find.I have verified that all the configurations (Entries in jboss-web.xml, web.xml) in other portlet are correct.
Any idea what could be going wrong?
-
14. Re: javax.naming.NameNotFoundException: jdbc not bound
wdfink Jun 28, 2012 2:35 AM (in response to madhuripotdar)Hi madhuripotdar,
welcome to the forum.
For your issue it will be better to open a new thread, describe your problem and add a link to other articles. Often the problems are different.
Also you should attach you DS configuration and the code how you access the datasource.
regards
Wolf