Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grails custom data source properties are not set when injecting the datasource in a service #12

Open
gabivis opened this issue Oct 18, 2020 · 2 comments

Comments

@gabivis
Copy link

gabivis commented Oct 18, 2020

Steps to Reproduce
define a dataSource in application.groovy (I use tomcat jdbc connection pooling)
dataSource {
pooled= true
username =
password =
...
properties {
...
maxActive=16
testOnBorrow=true
testWhileIdle=true
}
}
Reference the dataSource in a service
class MyService {
def dataSource
def myMethod() {
def sql = new Sql(dataSource)
...
}
}
Expected Behaviour
The datasource has the same custom properties as the ones set in application.groovy: i.e. testOnBorrow=true, testWhileIdle=true

Actual Behaviour
The properties inside the properties block are ignored and so testOnBorrow=false, testWhileIdle=false

Environment Information
Grails Version: 3.3.9
JDK Version: 1.8
Container Version (If Applicable): Tomcat

@vsachinv
Copy link

vsachinv commented Aug 2, 2022

@gabivis Did you find any solution for the same out of the box ?

@vsachinv
Copy link

vsachinv commented Aug 3, 2022

@gabivis As work around we have overridden bean like below in project resources.groovy.

  def domainClasses = grailsApplication.getArtefacts(DomainClassArtefactHandler.TYPE)
            .findAll { it.mappingStrategy != "none" && it.mappingStrategy == GrailsDomainClass.GORM }
            .collect { it.getClazz() }

    hibernateConnectionSourceFactory(HibernateFilterConnectionSourceFactory, domainClasses as Class[]) {
        dataSourceConnectionSourceFactory = ref('dataSourceConnectionSourceFactory')
    }

to avoid recreation of another dataSourceConnectionSourceFactory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants