title: Grails Oracle on Tomcat - JNDI config - error on InstanceAlreadyExistsException, etc
body: <p>I'm transitioning from Grails 2 to Grails 3, and dealing with an issue in regards to the Jndi datasource for Oracle on Tomcat, with a difference between Tomcat 7 and Tomcat 8.5.</p>
  
  <p>In short, with my Grails 3 app... I'm getting an error on Tomcat 8.5 that I don't get on Tomcat 7. With my Grails 2 app, I would not get the error on Tomcat 8.5 nor on Tomcat 7.</p>
  
  <p>This is the jndi config I would always use for Tomcat to connect to my Oracle DB, which is referenced from my Grails app: </p>
  
  <pre><code>    &lt;Resource name="jdbc/myGrails" auth="Container"
            type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
            url="jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = local)))"
            username="USER" password="PW"
            maxActive="100" maxIdle="30" maxWait="10000"
            /&gt;    
  </code></pre>
  
  <p>So when using this with my Grails 3 app on Tomcat 7... It works fine and I have no problems. But when using the same Grails 3 app on Tomcatt 8.5, I get an InstanceAlreadyExistsException, and the app doesn't startup. I came upon this page that details that error: 
  <a href="https://github.com/grails/grails-core/issues/9424" rel="nofollow noreferrer">https://github.com/grails/grails-core/issues/9424</a></p>
  
  <p>One of the suggested solutions on that thread was to add: </p>
  
  <pre><code>factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
  </code></pre>
  
  <p>To the JNDI configuration... I tried that, and would get a strange result: I would get an error/exception, but the app would run successfully, at least the parts I tested so far. This is the exception I get: </p>
  
  <pre><code>java.lang.ClassNotFoundException: Unable to load class: oracle.jdbc.OracleDriver from ClassLoader:java.net.URLClassLoader@13221655;ClassLoader:ParallelWebappClassLoader
  </code></pre>
  
  <p>Again, even with that exception, the app does run correctly and connect to the database. But I'm concerned what effect this exception would have on the app.</p>
  
  <p>The link mentioned above also suggests other solutions, such as setting: </p>
  
  <pre><code>spring.jmx.enabled: false
  </code></pre>
  
  <p>But before I keep re-trying different things... Is there a correct/standard way someone can suggest as to how to set the JNDI resource? For example, should I be adding the "factory" and then try to resolve the error that results from that? </p>
  
  <p>To state some details of my app: </p>
  
  <ul>
  <li>It's a Grails 3 app, using Grails 3.2.8 </li>
  <li>I want  to be able to deploy the WAR file for it to both Tomcat 7 and Tomcat 8.5</li>
  <li>It uses an Oracle database</li>
  <li>With the Grails 2 version of the app, I don't get any errors in Tomcat 7 nor in Tomcat 8.5</li>
  <li>With the Grails 3 version of the app, I don't get any errors in Tomcat 7. But in Tomcat 8.5 I do get errors, starting with the "InstanceAlreadyExists" exception</li>
  </ul>