将MySQL与Grails 2.0一起使用 - 查找外部连接器.jar

bMc*_*ees 4 mysql grails hsqldb

我正在使用Grails 2.0,而我无法让代码识别外部库.特别是MySQL驱动程序.

基本上每当我尝试将我的DataSource从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"
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Bur*_*ith 7

删除jar并BuildConfig.groovy改为使用依赖声明.不是拥有多个罐子的多个副本,而是每次下载一次并将它们缓存在常春藤缓存中并从那里引用它们要好得多.

BuildConfig.groovy有一个MySQL的例子; 只需取消注释即可,并在需要时更新版本.还要确保mavenCentral()取消注释存储库:

repositories {
    ...
    mavenCentral()
}

dependencies {
   ...
   runtime 'mysql:mysql-connector-java:5.1.16'
}
Run Code Online (Sandbox Code Playgroud)