我使用的是 Grails 2.0,但我无法让代码识别外部库。特别是 MySQL 驱动程序。
基本上,每当我尝试将数据源从 HSQLDB 更改为 MySql 时,问题就会发生。我下载了连接器 jar (5.0.8) 并将其放在 (project)/lib 目录中。我已验证 com.mysql.jdbc.Driver.class 文件位于 .jar 中。
每次我尝试运行该应用程序时,我都会收到错误消息:
由 ClassNotFoundException: com.mysql.jdbc.Driver 引起
非常感谢任何帮助。
dataSource {
pooled = true
//driverClassName = "org.h2.Driver"
//username = "sa"
//password = ""
driverClassName = "com.mysql.jdbc.Driver"
username = "bob"
password = "password"
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
//dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
//url = "jdbc:h2:mem:devDb;MVCC=TRUE"
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:mysql://localhost:3306/tekevent"
}
}
test {
dataSource {
dbCreate = "create-drop"
url = "jdbc:h2:mem:testDb;MVCC=TRUE"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:h2:prodDb;MVCC=TRUE"
pooled = true
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
}
}
}
}
最佳答案
删除 jar 并在 BuildConfig.groovy
中使用依赖声明。与其拥有许多 jar 的多个副本,不如每个都下载一次并将它们缓存在您的 Ivy 缓存中并从那里引用它们。
BuildConfig.groovy
已经有一个 MySQL 的例子;只需取消注释并在需要时更新版本。还要确保未注释 mavenCentral()
存储库:
repositories {
...
mavenCentral()
}
dependencies {
...
runtime 'mysql:mysql-connector-java:5.1.16'
}
关于mysql - 在 Grails 2.0 中使用 MySQL - 查找外部连接器 .jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8945755/