grails(二)简单项目示例

本文介绍了Grails框架中数据库配置的具体方法,并详细展示了针对MySQL的数据源配置示例。此外,还解决了因未正确配置数据库驱动而导致的应用启动失败问题。
grails(二)简单项目示例

1.数据库配置
配置文件 grails-app/conf/DataSource.groovy
A typical configuration for MySQL may be something like:
dataSource {
pooled = true
dbCreate = "update"
url = "jdbc:mysql://localhost/yourDB"
driverClassName = "com.mysql.jdbc.Driver"
username = "yourUser"
password = "yourPassword"
}

my configuration:
dataSource {
pooled = true
dbCreate = "update"
driverClassName = "com.mysql.jdbc.Driver"
username = "easygrails"
password = "easygrails"
}
hibernate {
cache.use_second_level_cache=true
cache.use_query_cache=true
cache.provider_class='com.opensymphony.oscache.hibernate.OSCacheProvider'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop','update'
url = "jdbc:mysql://www.sillycat.com/grails_dev"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://www.sillycat.com/grails_test"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://www.sillycat.com/grails_product"
}
}
}

启动报错:
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.codehaus.groovy.tools.RootLoader.findClass(RootLoader.java:146)

检查发现太兴奋了,数据库的驱动程序没有拷贝过来
拷贝文件mysql-connector-java-5.1.6.jar到lib目录下
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值