grails:data_source

Data Source

Data source can be setup in application.yml. You need to fill in 3 environments, and they are production, test, and development. Here is an example of it. You need to fill in your own * below.

Assume using MS SQL Server 2012.

dataSource:
    pooled: true
    jmxExport: true
    driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
    username: ********
    password: ********

environments:
    development:
        dataSource:
            logSql: true
#            dbCreate: create-drop
            dbCreate: none

            dialect: org.hibernate.dialect.SQLServer2012Dialect
            url: jdbc:sqlserver://***.***.***.***:1433;databaseName=*****;charset=utf8;useUnicode=yes&characterEncoding=UTF-8
            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
                jdbcInterceptors: ConnectionState
                defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED

    test:
        dataSource:
            dbCreate: update
            url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE

    production:
        dataSource:
            jndiName: "java:/**********"
            logSql: false
            dbCreate: none

from https://docs.grails.org/4.0.1/guide/conf.html


driverClassName - The class name of the JDBC driver

username - The username used to establish a JDBC connection

password - The password used to establish a JDBC connection

url - The JDBC URL of the database

dbCreate - Whether to auto-generate the database from the domain model - one of 'create-drop', 'create', 'update' or 'validate'

pooled - Whether to use a pool of connections (defaults to true)

logSql - Enable SQL logging to stdout

formatSql - Format logged SQL

dialect - A String or Class that represents the Hibernate dialect used to communicate with the database. See the org.hibernate.dialect package for available dialects.

readOnly - If true makes the DataSource read-only, which results in the connection pool calling setReadOnly(true) on each Connection

transactional - If false leaves the DataSource’s transactionManager bean outside the chained BE1PC transaction manager implementation. This only applies to additional datasources.

persistenceInterceptor - The default datasource is automatically wired up to the persistence interceptor, other datasources are not wired up automatically unless this is set to true

properties - Extra properties to set on the DataSource bean. See the Tomcat Pool documentation. There is also a Javadoc format documentation of the properties.

jmxExport - If false, will disable registration of JMX MBeans for all DataSources. By default JMX MBeans are added for DataSources with jmxEnabled = true in properties.

type - The connection pool class if you want to force Grails to use it when there are more than one available.

  • grails/data_source.txt
  • Last modified: 2019/12/27 10:18
  • by chongtin