Grails3,Grails4跟换数据库连接池为(HikariCP、Druid)

 

1、build.gradle

druid:

compile group: 'com.alibaba', name: 'druid', version: '1.1.21'
HikariCP:
compile 'com.zaxxer:HikariCP:3.3.1'

2、application.yml

dataSource:
    pooled: true
    jmxExport: true
    driverClassName: com.mysql.jdbc.Driver
    username: root
    password: '123456'
    type: com.alibaba.druid.pool.DruidDataSource
    properties:
        minIdle: 1
        maxActive: 20
        maxWait: 20000
        initialSize: 20
        testWhileIdle: true
        testOnBorrow: false
        testOnReturn: false
        removeAbandoned: true
        validationQuery: select 1
        useGlobalDataSourceStat: true
        poolPreparedStatements: true
        minEvictableIdleTimeMillis: 60000
        timeBetweenEvictionRunsMillis: 5000
        connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
        maxPoolPreparedStatementPerConnectionSize: 20
        filters: "stat,wall"

注意:type属性

    HikariCP:

com.zaxxer.hikari.HikariDataSource

   tomcat-jdbc

org.apache.tomcat.jdbc.pool.DataSource

   druid:

com.alibaba.druid.pool.DruidDataSource

3、最后在resource.groovy里添加

// 监控管理页面配置(管理用户名、密码)
    druidConsoleServlet(org.springframework.boot.web.servlet.ServletRegistrationBean) {
        servlet = bean(com.alibaba.druid.support.http.StatViewServlet)
        urlMappings = ["/druid/*"]
//        urlMappings = ["*.js","*.gif","*.jpg","*.png","*.css","*.ico","/druid/*"]
        initParameters = [
                "loginUsername": "root",
                "loginPassword": "123456",
                "allow": "127.0.0.1",
                "deny": ""
        ]
//        loadOnStartup = 2
    }

 

你可能感兴趣的:(java,grails,groovy)