Mariselvam
Mariselvam

Reputation: 1113

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

Upvotes: 3

Views: 4782

Answers (2)

sstendal
sstendal

Reputation: 3236

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"
        ...

Upvotes: 4

duffymo
duffymo

Reputation: 309008

You need to do more than just configure Spring.

I'd recommend reading Tomcat JNDI documentation and this.

Upvotes: 1

Related Questions