Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure a global JNDI datasource in Tomcat 6?

I'm struggling to configure a simple JNDI pooled datasource in Tomcat 6.0.32.

I want to create the datasource definition outside my web application artifact. Basically I don't want my application to know the credentials to access the database server. I was under the assumption that, like in Weblogic, it should be possible to create a "global" JNDI datasource in Tomcat, but so far I have been unsuccessful.

I have tried to add the datasource definition in CATALINA_HOME/conf/context:

<Resource name="jdbc/mydb"
 auth="Container"
 type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
 factory="oracle.jdbc.pool.OracleDataSourceFactory"
 url="jdbc:oracle:thin:@1.1.1.1.:xxx"
 user="xxxx"
 password="yyyy"/>

The result is that the server outputs the following line, when booting:

SEVERE: Null component Catalina:type=DataSource,path=/,host=localhost,class=javax.sql.DataSource,name="jdbc/mydb"

Any pointer would be appreciated.

like image 918
Luciano Fiandesio Avatar asked Dec 06 '22 21:12

Luciano Fiandesio


1 Answers

Move your data source configuration to server.xml <GlobalNamingResources>. (And don't forget to add the driver jar file to tomcat lib). Configure your context.xml so that all Application are aware of the global resource.

<Context>
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <ResourceLink global="jdbc/mydb" name="jdbc/mydb" type="javax.sql.DataSource"/>
</Context>
like image 140
Anthony Accioly Avatar answered Dec 10 '22 12:12

Anthony Accioly