I am developing a web application on Grails 3.2.2 with spring boot and hibernate and MS SQL Server as a backend database. I want my application to reconnect with the database automatically whenever SQL server comes back after a restart or any other issue.
This is how my application.yml file database-related properties look like:
development:
dataSource:
dbCreate: update
url: jdbc:jtds:sqlserver://machine_host_name:1433/db_name?autoReconnect=true
properties:
jmxEnabled: true
initialSize: 5
maxActive: 50
minIdle: 5
maxIdle: 25
maxWait: 10000
maxAge: 600000
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 60000
validationQuery: SELECT 1
validationQueryTimeout: 3
validationInterval: 15000
testOnBorrow: true
testWhileIdle: true
testOnReturn: false
defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED
And this is the JTDS library, I'm using in build.gradle file:
compile group: 'net.sourceforge.jtds', name: 'jtds', version: '1.3.1'
So, with these configurations too, my application is unable to reconnect to the MS SQL Server automatically after the restart of SQL Server service.
I found an issue when using the Javamelody plugin, compile 'org.grails.plugins:grails-melody-plugin:1.72.0' in build.gradle.
Once I commented this out it resolved reconnection issues to our database. May not be the same issue for you but perhaps for others it maybe.
来源:https://stackoverflow.com/questions/49027576/grails-3-automatic-reconnect-with-ms-sql-server