Grails Cookbook - A collection of tutorials and examples

How to make Grails use JNDI datasource with Tomcat

The most common way to configure database access in Grails is to hard code the connection properties inside Datasource.groovy. This is great for development purposes. But for production, we want a flexible way where admins can change which database to connect to, without needing to recompile the application.
The standard way of doing this is to leverage JNDI. We configure the database connection in the application server, and pass it to our Grails application. Below is an example on how to do it with Tomcat.