2
votes

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.

3

3 Answers

1
votes

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.

1
votes

I ended up working this out by trial and error.

It seems when you are using a local resource reference, you have to refer to it using the "java:comp/env/.." prefix, so my java code worked when I made the following changes:

Context initialContext = new InitialContext();
Object resource = initialContext.lookup("java:comp/env/localds");
dataSource = (DataSource) resource; 

Hope this is useful if anyone else is having similar problems

0
votes

There are really not many topics related to this error, and I have recently faced it when migrating from old Jboss version to WildFly 10.

I have found out that I can grep through the server.log to discover the correct string to use in lookup.