First of all, make sure you’re looking at the Tomcat 5.5 JNDI HowTo, not the Tomcat 5, and definitely not Tomcat 4. Yes, I know this sounds obvious, but once you start googling you’ll find it’s hard to distinguish the versions.
Place a context definition in /META-INF/context.xml – this is the preferred 5.5 per-application method as indicated here. The context file will be copied when deployed to [tomcat]/conf/Catalina/localhost/[webapp_name].xml.
This context file is the where the majority of the jndi configuration will take place. Any datasources configured here will need access to the identified driver class. Put your jars in $CATALINA_HOME/common/lib.
Example:
<context
crossContext="true"
reloadable="true"
displayName="Barack's Datasource" >
<resource
name="aspiring.presidentDS"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
maxIdle="2"
maxWait="5000"
validationQuery="select count(*) from elections.election_name"
username="bobama"
password="top_secret"
url="jdbc:oracle:thin:@aspiring.com:1525:bobama"
maxActive="20"
removeAbandoned="true"
removeAbandonedTimeout="60"
logAbandoned="true"/>
</context>
Important Note: Prior to Tomcat 5.5, a “path” attribute was required for Context elements (starting with 5.5, the path attribute must not be used except when statically defining a Context in server.xml, as it will be inferred from the Context fragment filename.
Note: Apparently Loggers are not configured in within the Context element anymore.
Note: While the [appname].xml is added to
As far as spring goes, the only change is the need to prepend java:/comp/env/ to the jndi name. So for example, something like this:
<bean id="webappDataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="com.aspiring.present.bobamaDS" /> </bean>
will become this:
<bean id="webappDataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="java:/comp/env/com.aspiring.president.bobamaDS" /> </bean>
Resources:
Tomcat 5.5 Classloader explanation
Post a Comment