tags:

views:

295

answers:

2

I am trying to bind connection to the DB using JNDI in my application that runs on JBoss. I did the following:

  1. I created the datasource file oracle-ds.xml filled it with the relevant xml elements:
<datasources>
   <local-tx-datasource>
     <jndi-name>bilby</jndi-name>
     ...
    </local-tx-datasource>
</datasources>

and put it in the folder \server\default\deploy

  1. Added the relevant oracle jar file

  2. than in my application I performed:

JndiObjectFactoryBean factory = new JndiObjectFactoryBean();

 factory.setJndiName("bilby");
 try{
     factory.afterPropertiesSet();
     dataSource = factory.getObject();
 }
 catch(NamingException ne) {
     ne.printStackTrace();
 }

and this cause the error:

javax.naming.NameNotFoundException: bilby not bound

then in the output after this error occured I saw the line:

18:37:56,560 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jb oss.jca:service=DataSourceBinding,name=bilby' to JNDI name 'java:bilby'

So what is my configuration problem? I think that it may be that JBoss first loads and runs the .war file of my application and only then it loads the oracle-ds.xml that contain my data-source definition. The problem is that they are both located in the same folder. Is there a way to define priority of loading them, or maybe this is not the problem at all.

Any idea?

A: 

You should use such construction to call Datasource: java:bilby.

You can read more about that here:

Naming and Directory (JNDI) - JBOSS jndi Datasource: jdbc not bound

Lukasz Stelmach
I tried the suggestion from both answers.I looked at the list() print from the jmx-console and saw that 'bilby' is registered under java:Namespace.I tried to call this connection by:factory.setJndiName("java:bilby"); factory.setJndiName("java/bilby"); factory.setJndiName("jdbc/bilby"); But none of them managed to find the jndi resource!Any other suggestions?
Spiderman
See continuation of this tread at:http://stackoverflow.com/questions/2843218/problem-configure-jboss-to-work-with-jndi2
Spiderman
Maybe you can check if your connection exits in JNDI tree. You can use twiddle command or jmx-console. Here you have example how to use twiddle:twiddle.sh invoke jboss:service=JNDIView list trueIf you have secure jmx-console you should pass credential using -u or -p parameters. If your server is running somewhere else that localhost you should also set -s parameter.PS. Sorry for answering here, but I cannot add comments on your new thread and I am pretty sure that it is not an answer :)
Lukasz Stelmach
This is part of the frustration - that I see the datasource exist in the Tree. I run JBoss locally on my machine and I am able to see it through the JBoss web-console.It's under System-->JMX Mbeans --> jboss.jdbc-->jboss.jdbc:service=metadata,datasource=bilbythe stateString of it is 'Started'so it seems that it's up and running only I can't approach it from my application )-:
Spiderman
I forgot to mention that I am working with JBoss version 4.2.3.GA
Spiderman
OK, this is the correct answer in normal cases. the Datasource is by 'java:<jndi-name>' In my specific case I have got conflicts between JBoss jars in my WEB-INF/lib to jars of JBoss server that cause JNDI to work improperly.
Spiderman
A: 

To check how the datasource is bound in the JNDI tree you should use the jmx-console http://localhost8080/jmx-console/HtmlAdaptor?action=inspectMBean&amp;name=jboss%3Aservice%3DJNDIView and invoke the list() method.

Datasources are registered under "jdbc". In your case "jdbc/bilby"

EDIT: That was an example that works for me without spring. Now found this example which injects a more complete JNDI name.

<bean id="idDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:comp/env/jdbc/bilby" />
</bean>
stacker