Tomcat JNDI Setting

Environment

Tomcat 7.0.70

JDK 1.6.0.45

ojdbc6 11.2.0.1

Spring 4.3.1

Process

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"
 url="jdbc:oracle:thin:@[IP]:[Port]:[SID]" 
 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

<resource-ref>
 <res-ref-name>jdbc/myDS</res-ref-name>
 <res-type>javax.sql.DataSource</res-type>
 <res-auth>Container</res-auth>
</resource-ref>

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"/>
</bean>

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

Reference

http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html

http://tiantian0521.blog.163.com/blog/static/4172088320117294265766/

https://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html

https://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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