Tuesday, May 22, 2012
JNDI Setup for Tomcat 6 with Spring Application for DB2 and MySQL
Assuming your tomcat location is C:\apache-tomcat-6.0.35
Step1
Copy JDBC driver to “C:\apache-tomcat-6.0.35\lib”
Example:
In case of MySQL it might be mysql-connector-java-5.1.18.jar
In case of DB2 it could be db2jcc4-9.7.2.jar etc.
Step 2
Open C:\apache-tomcat-6.0.35\conf\server.xml and put following <Resource />
Inside <GlobalNamingResources>
<GlobalNamingResources>
<Resource name="jdbc/myjdb" auth="Container" type="javax.sql.DataSource"
username="" password="" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/databaseName"maxActive="15"
maxIdle="7" maxWait="5000" validationQuery="select 1"/>
…..
GlobalNamingResources>
Example case for MySQL
<Resource
name="jdbc/myjdb" auth="Container" type="javax.sql.DataSource"
description="My Test database"
username="root" password="******"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/databaseName"
maxActive="15"
maxIdle="7"
maxWait="5000"
validationQuery="select 1"/>
Example case for DB2
<Resource
name="jdbc/myjdb" auth="Container" type="javax.sql.DataSource"
description="My Test database"
username="root" password="******"
driverClassName="com.ibm.db2.jcc.DB2Driver"
url="jdbc:db2://servername:port/databaseName"
maxActive="15"
maxIdle="7"
maxWait="5000"
validationQuery="select 1"/>
Step 3
Open C:\apache-tomcat-6.0.35\conf\Context.xml,
Copy <ResourceLink …> inside
For both MySQL or DB2, example is same:
<Context>
…..
<ResourceLink name="jdbc/myjdb"
type="javax.sql.DataSource"
global="jdbc/myjdb"/>
Context>
step 4
Inside application context, in my case it was
src\main\resources\META-INF\spring\appContext.xml
Just add following line:
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/myjdb"/>
and at top of the context you might required to add
<beans xmlns:jee="http://www.springframework.org/schema/jee"http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd>
step 5
create a file jndi.properties on the class path,
in my case src\main\resources\META-INF\ jndi.properties
I just created that but still haven’t put any of these values which looks like below.
Well, my application is working even putting any of these values right now.
jndi.properties
|
java.naming.factory.initial=
java.naming.factory.object=
java.naming.factory.state=
java.naming.factory.control=
java.naming.factory.url.pkgs=
java.naming.provider.url=
java.naming.dns.url=
|
Subscribe to: Post Comments (Atom)
No comments:
Links to this post