Spring MVC JdbcTemplate with JNDI Datasource in Tomcat Server
Configuring a datasource through JNDI mapping in Tomcat is beneficial since the database configuration remains independent of application. Configuring a JNDI in Tomcat and using the reference within Spring application to create a JdbcTemplate object achieves the object of loose coupling.
Any database configuration changes would be done at the Tomcat end without affecting the application deployed.
Below are the steps to define a JNDI in Tomcat and use in Spring configuration XML file to map with JdbcTemplate:
1) Create a JNDI configuration in Tomcat:
Open context.xml file in /conf folder and add a Resource entry