java.lang.ClassNotFoundException: com.mysql.jdbc.Driv5r

java.lang.ClassNotFoundException: com.mysql.jdbc.Driv5r

我正在尝试 运行 一个 grails 应用程序,然后在 运行-app.

| Loading Grails 2.1.1

| Configuring classpath

Resolving [test] dependencies...

Resolving [runtime] dependencies...

| Configuring classpath.

| Environment set to development.....

| Packaging Grails application.....

| Compiling 54 source files

| Compiling 54 source files..

| Compiling 43 source files

warning: Implicitly compiled files were not subject to annotation processing.
Use -proc:none to disable annotation processing or -implicit to specify a policy for implicit compilation.
1 warning
| Compiling 43 source files.....
| Running Grails application



Cannot load JDBC driver class 'com.mysql.jdbc.Driv5r'
java.lang.ClassNotFoundException: com.mysql.jdbc.Driv5r
at java.net.URLClassLoader.run(URLClassLoader.java:202)
.
.
.
.


  at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:901)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy:185)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)

为什么拼写的是'com.mysql.jdbc.Driv5r'而不是'com.mysql.jdbc.Driver'

尝试了 grails clean Refresh Dependencies,但仍然有同样的错误,是否有任何外部方法可以添加此驱动程序 class,我正在研究 GGTS。

检查您执行此操作的代码。

Class.forName(driver);// here Check variable "driver"
 String driver="com.mysql.jdbc.Driver"; // here you might have typed "com.mysql.jdbc.Driv5r"

Class.forName("com.mysql.jdbc.Driver");//here you might have typed com.mysql.jdbc.Driv5r

All other looks fine.. So this may be the reason.

看来你粗心了。com.mysql.jdbc.Driv5r really.The 造成这种情况的主要原因是 datasource.groovy 中 driverClassName 定义中的拼写错误。

dataSource {
    pooled = true
    driverClassName = "com.mysql.jdbc.Driv5r"
    dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
    url = dataSourceProperties.getProperty("datasource.url")
    username = dataSourceProperties.getProperty("datasource.username")
    password = dataSourceProperties.getProperty("datasource.password")
}

driverClassNamecom.mysql.jdbc.Driv5r 更正为 com.mysql.jdbc.Driver

除此之外,还要确保您是否在 BuildConfig.groovy.

中添加了 mysql 的依赖项