Java – NameNotFoundException mapping JNDI Datasource to Local name

javajndiweblogic12c

Im having trouble mapping a Weblogic (12c) defined JNDI Datasource to a local jndi name.

I have a datasource in weblogic mysql datasource defined as "mysqltestds", and I want to map i within a web application to a local name "localds"

My web.xml properties are

<resource-ref>
   <res-ref-name>localds</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
</resource-ref>

with the weblogic.xml

<weblogic-web-app>
   <resource-description>
      <res-ref-name>localds</res-ref-name>
      <jndi-name>mysqltestds</jndi-name>lls
   </resource-description>
</weblogic-web-app>

When I get the datasource using the global name "mysqltestds" it works correctly.

Context initialContext = new InitialContext();
Object resource = initialContext.lookup("mysqltestds");
dataSource = (DataSource) resource; 

However, when I try "localds" it fails with the error:

Context initialContext = new InitialContext();
Object resource = initialContext.lookup("localds");
dataSource = (DataSource) resource; 

javax.naming.NameNotFoundException: Unable to resolve 'localds'. Resolved ''; remaining name 'localds'

Can anyone help. I followed the directions in this stackOverflow question Tomcat vs Weblogic JNDI Lookup , but I haven't had any success.

Best Answer

couple things.
first thing to check is make sure you actually deployed the datasource to the server that you are accessing. because if you havent you will get that exact message.

also if you look in the console goto the server page and click the server you are working with.

then there is a link on the page called something like jndiViewer you should be able to browse for you datasource to confirm its location.

Related Topic