2

I have an existing spring framework based web application. I want to use JNDI on Tomcat 6 and Oracle server for it. Please explain a simple step by step procedure for the same.

Aniruddha
  • 308
  • 2
  • 11
  • 1
    +1 for your question.However,an application server like JBoss and WAS gives you many custmized features such as DB connection pooling will really make your application perform well for heavy load applications. – Kumar Abhinav Oct 20 '14 at 15:25

2 Answers2

1

Please follow these steps:

  1. Add the following code in the tag <GlobalNamingResources> in the following file:

apache-tomcat-6.0.37/conf/server.xml

<Resource name="jdbc/dbName" auth="Container" type="javax.sql.DataSource"
                   username="xyz" password="abcd"
                   url="jdbc:url"
                   driverClassName="oracle.jdbc.driver.OracleDriver"
                   initialSize="5" maxWait="5000"
                   maxActive="120" maxIdle="5"                   
                poolPreparedStatements="true"/>

  1. Add the following code in the tag <Context> in the following file

apache-tomcat-6.0.37/conf/context.xml

<ResourceLink name="jdbc/dbName" global="jdbc/dbName" type="javax.sql.DataSource"/>

  1. Add the following code in the file

applicationContext.xml

<jee:jndi-lookup id="dataSource" jndi-name="jdbc/dbName" expected-type="javax.sql.DataSource" />

  1. Make sure the <beans:xmlns tag in the applicationContext.xml has the following data:

xmlns:jee="http://www.springframework.org/schema/jee"

and these schemas in their xsi:schemaLocation :

http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/beans

  1. Ensure that

ojdbc14.jar

is present in the folder:

apache-tomcat-6.0.37\lib


  1. Remove the previous database connection parameters defined in your application(property files/dataSource beans defined in applicationContext.xml).

That should be enough.

Aniruddha
  • 308
  • 2
  • 11
0

This was a great knowledge, Can you please also share how to condigure JNDI for external LDAP datasource?

The database JNDI worked finne for me after following your steps. You can get more details in below link. External LDAP JNDI connectivity using Tomcat

Thanks Anny

Community
  • 1
  • 1
annonymus
  • 9
  • 2