grails 配置mysql

本文介绍如何在Grails应用中配置MySQL数据库,包括DataSource.groovy文件的设置、Hibernate缓存配置以及不同环境下的数据库创建策略。同时,还提供了如何在BuildConfig.groovy中添加MySQL连接器依赖的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

grails 配置mysql数据库

  • 修改DataSource.groovy
dataSource {
    pooled = true
    jmxExport = true
    driverClassName = "com.mysql.jdbc.Driver"
    username = "root"
    password = "123456"
}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
    cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory'
    singleSession = true
    flush.mode = 'manual'
}
environments {
    development {
        dataSource {
            dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:mysql://localhost:3306/login_demo?useUnicode=true&characterEncoding=UTF8"
        }
    }
    test {
        dataSource {
            dbCreate = "update"
            url = "jdbc:mysql://localhost:3306/login_demo?useUnicode=true&characterEncoding=UTF8"
        }
    }
    production {
        dataSource {
            dbCreate = "update"
            url = "jdbc:mysql://localhost:3306/login_demo?useUnicode=true&characterEncoding=UTF8"
        }
    }
  • 在BuildConfig.groovy中的dependencies里添加 runtime “mysql:mysql-connector-java:5.1.6”
 dependencies {
        runtime 'mysql:mysql-connector-java:5.1.6'
        test "org.grails:grails-datastore-test-support:1.0.2-grails-2.4"
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值