Gabi
Gabi

Reputation: 687

Injecting datasource in grails 3 ignores additional properties set in application.groovy

I'm using grails 3.3.9 and I have a datasource in application.groovy defined as:

    username = ...
    password = ...
    ...
    properties {
      ...
      maxActive=16 
      testOnBorrow=true
      testWhileIdle=true
      ...
   }

I want to inject the datasource in a service so I inject it by defining:

class MyService {
   def dataSource
  
    def myMethod() {
       def sql = new Sql(dataSource)
    ...
    }
}

The problem is that the properties set in application.groovy are ignored and the defaults are used: i.e. maxActive=10, testOnBorrow=false, testWhileIdle=false.

I wonder how can I inject the datasource and keep the properties defined in application.groovy...

Later edit

It looks like the cause of this issue was actually the grails hibernate-filter-plugin. Without it the datasource looks good.

Upvotes: 0

Views: 134

Answers (1)

Orubel
Orubel

Reputation: 334

Would need to see the full datasource. Might be a problem further up. Also, if you are defining the datasource in your yaml, it will overwrite your application.groovy properties (I believe)

Upvotes: 0

Related Questions