Q:

Load Spring Database Properties from Tomcat's lib dir

I want to put the property file with database connection string in the lib directory of Tomcat and load this file for datasource in Spring XML definition. Is there a way to do this? (because I know how to load from the classpath).

A:

Yes this is perfectly possible as files available in tomcat lib are available under classpath to web app. we are using this already in project. 
 <util:properties id="appConfig" location="classpath:app.properties" />

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="#{appConfig['app.db.url']}" />
    <property name="username" value="#{appConfig['app.db.user']}" />
    <property name="password" value="#{appConfig['app.db.password']}" />
    <property name="testOnBorrow" value="true" />
    <property name="testOnReturn" value="false" />
    <property name="testWhileIdle" value="true" />
    <property name="minEvictableIdleTimeMillis" value="60000"></property>
    <property name="validationQuery" value="SELECT 1" />
</bean>

