2016-06-10 49 views
-2

我想運行一個grails應用程序,並在做完run-app之後。java.lang.ClassNotFoundException:com.mysql.jdbc.Driv5r

| 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$1.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的清潔刷新依賴性,但仍相同的錯誤是沒有任何外部添加這個驅動類的方法,我正在研究GGTS。

+0

手動方法是將msyql-connect-XXX.jar放入lib文件夾並卸載mysql插件 - – Vahid

+0

請包含觸發此錯誤的代碼。 –

回答

2

看來你是粗心。 com.mysql.jdbc.Driv5r really。主要原因是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.Driv5rcom.mysql.jdbc.Driver

除此之外,還要確保您是否在BuildConfig.groovy中爲mysql添加了依賴項。

0

檢查你的代碼,你在做什麼。

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

OR

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

所有其他看起來不錯。所以這可能是原因。