2014-01-14 32 views
1

我得到ClassNotFoundException的在我的項目/ lib中有oracle驅動程序.jar)。的Grails無法加載oracle.jdbc.driver.OracleDriver和--refresh依賴性不起作用

我已經看到了類似的問題here和其他地方,答案似乎總是跑--refresh-depdencies

然而,我發現,這樣做只能用於--refresh依賴性之後只有一個時間運行。隨後的任何時間我都會運行應用程序,我再次獲得ClassNotFoundExceptionoracle.jdbc.OracleDriver,直到我再次運行--refresh-dependencies。通過運行--refresh-dependencies每次我即將運行應用程序,我仍然可以運行,但它很煩人。

我正在運行grails 2.3.0。

Grails的輸出而不必做--refresh依賴性之前立即運行的應用程序:

| Loading Grails 2.3.0 
| Configuring classpath. 
| Environment set to development..... 
| Packaging Grails application..... 
| Running Grails application 
Configuring Spring Security Core ... 
... finished configuring Spring Security Core 
Configuring Spring Security LDAP ... 
... finished configuring Spring Security LDAP 
Configuring Spring Security CAS ... 
... finished configuring Spring Security CAS 
| Error 2014-01-14 15:15:14,235 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is java.sql.SQLException: oracle.jdbc.OracleDriver 
Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is java.sql.SQLException: oracle.jdbc.OracleDriver 
    Line | Method 
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 166 | run  in java.util.concurrent.FutureTask 
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor 
| 615 | run  in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 722 | run . . . in java.lang.Thread 
Caused by BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is java.sql.SQLException: oracle.jdbc.OracleDriver 
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 166 | run  in java.util.concurrent.FutureTask 
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor 
| 615 | run  in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 722 | run . . . in java.lang.Thread 
Caused by BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is java.sql.SQLException: oracle.jdbc.OracleDriver 
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 166 | run  in java.util.concurrent.FutureTask 
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor 
| 615 | run  in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 722 | run . . . in java.lang.Thread 
Caused by BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is java.sql.SQLException: oracle.jdbc.OracleDriver 
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 166 | run  in java.util.concurrent.FutureTask 
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor 
| 615 | run  in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 722 | run . . . in java.lang.Thread 
Caused by BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is java.sql.SQLException: oracle.jdbc.OracleDriver 
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 166 | run  in java.util.concurrent.FutureTask 
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor 
| 615 | run  in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 722 | run . . . in java.lang.Thread 
Caused by MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is java.sql.SQLException: oracle.jdbc.OracleDriver 
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 166 | run  in java.util.concurrent.FutureTask 
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor 
| 615 | run  in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 722 | run . . . in java.lang.Thread 
Caused by SQLException: oracle.jdbc.OracleDriver 
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 166 | run  in java.util.concurrent.FutureTask 
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor 
| 615 | run  in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 722 | run . . . in java.lang.Thread 
Caused by ClassNotFoundException: oracle.jdbc.OracleDriver 
->> 175 | findClass in org.codehaus.groovy.tools.RootLoader 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 423 | loadClass in java.lang.ClassLoader 
| 147 | loadClass in org.codehaus.groovy.tools.RootLoader 
| 356 | loadClass in java.lang.ClassLoader 
| 266 | forName . in java.lang.Class 
| 334 | innerRun in java.util.concurrent.FutureTask$Sync 
| 166 | run . . . in java.util.concurrent.FutureTask 
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor 
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker 

^ 722 | run  in java.lang.Thread 

,做--refresh依賴性之後:

| Loading Grails 2.3.0 
| Configuring classpath. 
| Environment set to development..... 
| Packaging Grails application..... 
| Running Grails application 
Configuring Spring Security Core ... 
... finished configuring Spring Security Core 
Configuring Spring Security LDAP ... 
... finished configuring Spring Security LDAP 
Configuring Spring Security CAS ... 
... finished configuring Spring Security CAS 
| Server running. Browse to http://localhost:8080/loggity-rest 
+1

嘗試升級到2.3.4或至少是2.3.0以外的版本 - 兩個版本之間修復了很多錯誤 –

+0

我升級到2.3.4,並且仍然遇到同樣的問題。 – shazbot

回答

0

這看起來像一個問題在2.3中默認使用了新的Aether依賴管理器。它的速度比一般的速度快很多,但常常不支持的少數Ivy功能。

我能夠從以太改變常春藤在BuildConfig.groovy得到這個工作:

grails.project.dependency.resolver = "ivy" 
+0

不幸的是,這導致我沒有任何改變。 – shazbot

+1

嘗試運行'grails compile --refresh-dependencies' –

+0

我已經這樣做了,因爲這樣做是複製問題的一部分。和以前一樣,當運行grails編譯--refresh-dependencies時,當run-app立即運行時,不會出現問題,但是隨後運行run-app的任何時間都會出現問題,除非grails編譯--refresh-dependencies再次運行。 – shazbot

1

我不認爲這是一個「答案」我自己的問題,但我在這裏張貼作爲一個可能的解決方案,以防其他人遇到此問題。

我能夠通過通過BuildConfig.groovy而不是使用/ lib文件夾拉動我的oracle驅動程序來解決這個問題。

我不認爲這是一個解決方案的原因是,爲了做到這一點,您需要一個存放oracle驅動程序工件的存儲庫,它不在任何公共存儲庫中,也不允許由於「吝嗇」在甲骨文的一部分。

我的公司有一個私人存儲庫,我可以使用該存儲庫,並由我們的CI服務器共享,並且此解決方案僅適用於那些有權訪問某種私人存儲庫的人。我把我的BuildConfig.groovy幾乎是你所期望的:

runtime "com.oracle:ojdbc6:11.2.0.1.0" 

那些在它仍然需要一個解決無法使用此解決方案由於沒有提供與Oracle驅動程序jar的倉庫使用/ lib時出現的問題。

1

我有類似的問題,一次它會運行應用程序很好,但只要我重新啓動它會拋出「池連接」異常。

在BuildConfig.groovy中添加以下行修復了我的問題。不知道爲什麼它缺少開始。

grails.project.dependency.resolver = "maven" // or ivy 
0

從此改變行我BuildConfig

runtime "com.oracle:ojdbc6:11.2.0.1.0" 

這(離開了COM):

runtime "oracle:ojdbc6:11.2.0.1.0" 

爲我工作。