Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring not able to find JNDI data source

I am developing a spring web application . A JAR file which I use in my application , is looking for DataSource using JNDI. I configured the element in my tomcat's server.xml. The configuration is as below ,

<GlobalNamingResources>
  <Resource name="jdbc/abcd" 
            auth="Container" 
            type="javax.sql.DataSource" 
            maxActive="70"
            maxWait="10000" 
            username="xxxx" password="yyyy" 
            validationQuery="SELECT 1 from dual"
            driverClassName="oracle.jdbc.driver.OracleDriver" 
            url="jdbc:oracle:thin:@xx.xxx.xx.xx:xxxx:zzzz"
            testOnBorrow="false"
            testOnReturn="false"
            testWhileIdle="true"
            timeBetweenEvictionRunsMillis="120000"
            minEvictableIdleTimeMillis="3600000"
  />
</GlobalNamingResources>

The Resource name configured above , "jdbc/abcd" is the same which the JAR is looking for, But its not able to find this configured data source . Does anyone know what could be the reason ?

Am getting the below exception ,

javax.naming.NameNotFoundException: Name jdbc is not bound in this Context

like image 575
Mariselvam Avatar asked Mar 04 '26 14:03

Mariselvam


2 Answers

You need to define a ResourceLink in the web application context that makes the global resource visible to the web application.

<ResourceLink 
        name="nameThatIsVisibleToTheWebApplication"
        global="theGlobalName"
        ...
like image 198
sstendal Avatar answered Mar 06 '26 12:03

sstendal


You need to do more than just configure Spring.

I'd recommend reading Tomcat JNDI documentation and this.

like image 25
duffymo Avatar answered Mar 06 '26 14:03

duffymo