Luciano Fiandesio
Luciano Fiandesio

Reputation: 10207

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.

Upvotes: 4

Views: 24626

Answers (2)

user2894012
user2894012

Reputation:

Your mistake: user="xxxx", you need to write username="xxxx" instead.

Upvotes: 0

Anthony Accioly
Anthony Accioly

Reputation: 22461

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>

Upvotes: 15

Related Questions