Tomcat JNDI Setting


Tomcat 7.0.70



Spring 4.3.1


Step 1. Put ojdbc6.jar under Tomcat/lib

Step 2. Add Resource to Tomcat/conf/context.xml

<Resource name="jdbc/myDS" auth="Container" 
 type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
 username="[user]" password="[pwd]"
 maxActive="20" maxIdle="10" maxWait="-1"/>

oracle.jdbc.driver.OracleDriver is desupported after Oracle JDBC release 9.0.1, using oracle.jdbc.OracleDriver instead.

Step 3. (Optional) Add resource-ref to WEB-INF/web.xml


According to Tomcat, “If a resource has been defined in a <Context> element it is not necessary for that resource to be defined in /WEB-INF/web.xml. However, it is recommended to keep the entry in /WEB-INF/web.xml to document the resource requirements for the web application.”

Step 4. Edit your DataSource bean

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
 <property name="jndiName" value="java:/comp/env/jdbc/myDS"/>

In Tomcat, JNDI name should append “java:/comp/env/”, but in Weblogic, use the exact JNDI Name setting in the Data Sources section.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s