title: Bind grails datasource to jndi-name
body: <p>Configuring a Grails v2.2.4 app with mysql database to use JDBC connection pool and JavaMelody monitor. Everything seems to run properly in GGTS v3.4.0 but unable to deploy a WAR file successfully.</p>
  
  <p>Config.groovy contains:</p>
  
  <pre><code>grails.naming.entries = ['jdbc/myDB': [
  type: "javax.sql.DataSource",
  factory: "org.apache.tomcat.jdbc.pool.DataSourceFactory",
  auth: "Container",
  driverClassName: 'com.mysql.jdbc.Driver',
  username: &lt;username&gt;,
  password: &lt;password&gt;,
  url: &lt;database_url&gt;,
  &lt;connection pool settings&gt; ]  ]
  </code></pre>
  
  <p>In DataSource.groovy:</p>
  
  <pre><code>dataSource { 
  jndiName = "java:comp/env/jdbc/myDB"
  pooled = true
  useUnicode="yes"
  characterEncoding="UTF-8"
  dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
  dbCreate = 'update' // one of 'create', 'create-drop', 'update', 'validate'
  }
  hibernate {
  cache.use_second_level_cache = true
  cache.use_query_cache = false
  cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
  }
  </code></pre>
  
  <p>Can somebody provide direction on the proper syntax and location of config statement(s) (within the IDE) to bind dataSource to jndi? This app runs on Cloud Foundry so we need to stuff desired Tomcat settings into the war file (i.e., we cannot change Tomcat xml).</p>
  
  <p>SOLUTION:</p>
  
  <p>Move the grails.naming entries block from config.groovy to web-app\META-INF\context.xml</p>
  
  <pre><code>&lt;Resource name="jdbc/myDB" auth="Container" type="javax.sql.DataSource"
  driverClassName="com.mysql.jdbc.Driver"
  factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" 
  username="[username]" password="[password]" url="[database_url]" 
  [connection pool settings:  property="value" ]  /&gt;    
  </code></pre>