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目录下
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目录下
本文介绍了Grails框架中数据库配置的具体方法,并详细展示了针对MySQL的数据源配置示例。此外,还解决了因未正确配置数据库驱动而导致的应用启动失败问题。
911

被折叠的 条评论
为什么被折叠?



