title: Grails 4.0.3 Multiple Datasources - Second datasource not available in service
body: <p>I've followed the instructions/example in the Grails Doc (<a href="https://docs.grails.org/4.0.3/guide/conf.html#multipleDatasources" rel="nofollow noreferrer">https://docs.grails.org/4.0.3/guide/conf.html#multipleDatasources</a>) and it still uses the default dataSource.</p>
  <p>My application.yml contains:</p>
  <pre><code>dataSource:
      pooled: true
      jmxExport: true
      dbCreate: validate
      url: jdbc:oracle:thin:@XXX.XX.X.XXX:XXXX:TEST
      username: username1
      password: password1
      driverClassName: oracle.jdbc.OracleDriver
      dialect: org.hibernate.dialect.Oracle10gDialect
      properties:
          jmxEnabled: true
          initialSize: 5
          maxActive: 50
          minIdle: 5
          maxIdle: 25
          maxWait: 10000
          maxAge: 600000
          timeBetweenEvictionRunsMillis: 5000
          minEvictableIdleTimeMillis: 60000
          validationQuery: SELECT 1 FROM DUAL
          validationQueryTimeout: 3
          validationInterval: 15000
          testOnBorrow: true
          testWhileIdle: true
          testOnReturn: false
          jdbcInterceptors: ConnectionState
          defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED
  dataSources:
      identityDb:
          url: jdbc:oracle:thin:@YYY.YY.YY.YYY:YYYYY:IDENT
          username: username2
          password: password2
  </code></pre>
  <p>And my service is defined as follows:</p>
  <pre><code>class PictureService {
      def grailsApplication
      def assetResourceLocator
      static dataSource = &quot;identityDb&quot;
  
      def getPictures( identifications ) {
          // Loop through all ids
          for( i in identifications ) {
              //try {
                  Sql sql = Sql.newInstance( dataSource )
      ...
  </code></pre>
  <p>It throws this stack dump:</p>
  <pre><code>ORA-00942: table or view does not exist
  . Stacktrace follows:
  
  java.lang.reflect.InvocationTargetException: null
          at org.grails.core.DefaultGrailsControllerClass$ReflectionInvoker.invoke(DefaultGrailsControllerClass.java:211)
          at org.grails.core.DefaultGrailsControllerClass.invoke(DefaultGrailsControllerClass.java:188)
          at org.grails.web.mapping.mvc.UrlMappingsInfoHandlerAdapter.handle(UrlMappingsInfoHandlerAdapter.groovy:90)
          at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
          at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
          at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
          at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
          at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
          at org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:77)
          at org.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
          at java.lang.Thread.run(Thread.java:748)
  Caused by: java.sql.SQLException: ORA-00942: table or view does not exist
  </code></pre>
  <p>When I dump out the connection string information for dataSource, I can see that it's the first datasource listed and not the identityDb datasource. I'm not using domain classes or GORM and am just writing the SQL directly. Any help with this would be appreciated!</p>