Search code examples
connection-poolingtomcat7

how to config JDNI in tomcat7


I just have a test. Config jndi in $CATALINA_HOME/conf/context.xml like below:

<Resource name="jdbc/db" auth="Container" type="javax.sql.DataSource"         driverClassName="oracle.jdbc.OracleDriver"     url="jdbc:oracle:thin:@tnsname" username="test"     password="test" maxActive="20" maxIdle="10" defaultAutoCommit="false" maxWait="5000"     validationQuery="select 1 from dual" testWhileIdle="true" timeBetweenEvictionRunsMillis="5000" removeAbandoned="true" removeAbandonedTimeout="30" logAbandoned="true" /> 

and I didn't config it in any others places like $CATALINA_HOME/conf/server.xml or /WEB-INF/web.xml or WEB-INF/context.xml. But I still can use it normally in JAVA code.

But from http://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html, it seems that at least two files needed to be configed for JNDI.

So could anyone tell me how to config JDNI in tomcat with standard methods. Thanks!


Solution

  • You configured JNDI data source for your application correctly, in the context.xml file for your application. The capability to configure JNDI data sources in the web.xml is preserved in Tomcat 7.0 for compatibility with older versions of Tomcat and, if I'm not mistaken, older versions of Java EE spec.