And when Tech Op suggested to move configuration from project to them, I first started with setting up JNDI DataSource in Tomcat.
On Tomcat side, there are two places need to be configured:
1. Add the JDBC jar to Tomcat's library, for Tomcat 5.5, in common/lib directory.
2. Add the DataSource as a Resource to server.xml under GlobalNamingResources:
<Resource name="myApp" auth="Container"Note: removeAbandoned=”true”, removeAbandonedTimeout=”60” and logAbandoned=”true” is Tomcat’s recommended solution to prevent dB connection pool leaks.
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@<oracle db connection string>"
username="<user name>" password="<password>"
maxActive="10" maxIdle="5"
maxWait="60000" removeAbandoned="true"
removeAbandonedTimeout="60" logAbandoned="true"/>
On the project side, there are also two places need to be configured:
1. In the web application's root directory, create a META-INF directory if not exists. And add a context.xml to META-INF with following content:
<Context reloadable="true" >context.xml will be copied over to conf/Catalina/localhost with the the project's context name as file name if the file doesn't exist. So for the first time deployment, it is necessary to check the conf/Catalina/localhost directory and delete the context file if exists.
<ResourceLink name="jdbc/myApp" global="myApp" type="java.lang.Integer" />
</Context>
2. In Spring configuration:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">An alternative configuration with jee schema:
<property name="jndiName" value="java:comp/env/jdbc/myApp"/>
</bean>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">
...
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/myApp"/>
</beans>
No comments:
Post a Comment