5

I have a hard time setting up HikariCP in Grails 3.

The only thing I could realize by myself is that application.yml/dataSource.pooled must be false. The rest is kinda mystery:

  • This gist seems like configuration for Grails 2
  • Other SO questions are dealing with Grails 2 too - 1, 2
  • HikariCP issue with Grails 3 but with a crazy config

How can I setup HikariCP with Grails 3?

Amio.io
  • 20,677
  • 15
  • 82
  • 117
  • I've found by monitoring the connections at the server end (postgres in my instance) that by setting pooled = false will cause grails to bypass the hikari pool as well and create new connections on demand. It looks like it works, but connections don't ever seem to be sourced from the pool – David Feb 19 '18 at 02:53

1 Answers1

6

So I just got this working as expected. All you need to do is include the Hikari dependency, and set pooled: true in your application.yml.

Additional properties can be set on the Hikari connection pool by specifying them in the properties section on the dataSource

Do not create a dataSource bean in resources.groovy, as this will cause all sorts of problems if pooled is set to true, and is largely ignored if pooled is false (apart from consuming and leaving idle the entire pool of connections)

build.gradle extract:

...
compile 'com.zaxxer:HikariCP:2.7.7'
...

application.yml extract:

...
dataSource:
  pooled: true
  driverClassName: "org.postgresql.Driver"
  postgresql:
    extensions:
      sequence_per_table: false
  logSql: false
  dbCreate: ""
  username: "username"
  password: "password"
  url: "jdbc:postgresql://..."
  properties:
    maximumPoolSize: 30
    registerMbeans: true
    connectionTimeout: 30000
...

Its not clear to me exactly how grails/gorm detects the connection pool provider, and I'm not sure what would happen if you had two connection providers configured. I just made sure that the default tomcat dependency was missing from my build.gradle

# Remove this line from build.gradle if you have it
runtime 'org.apache.tomcat:tomcat-jdbc'
David
  • 511
  • 4
  • 14