【问题标题】:Grails cannot load oracle.jdbc.driver.OracleDriver and --refresh-dependencies does not workGrails 无法加载 oracle.jdbc.driver.OracleDriver 并且 --refresh-dependencies 不起作用
【发布时间】:2015-10-28 16:31:37
【问题描述】:

我得到 ClassNotFoundException:oracle.jdbc.OracleDriver 任何时候我在执行 grails run-app 之前没有立即执行 --refresh-dependencies(我的项目 /lib 中有 oracle 驱动程序 .jar) .

我在here 和其他地方看到过类似的问题,答案似乎总是运行 --refresh-depdencies

但是,我发现在 --refresh-dependencies 运行后,这样做只有效一次。以后每次运行应用程序时,我都会再次收到 ClassNotFoundException:oracle.jdbc.OracleDriver,直到我再次运行 --refresh-dependencies。通过每次我要运行应用程序时运行 --refresh-dependencies 我仍然可以运行,但这很烦人。

我正在运行 grails 2.3.0。

grails 在 run-app 之前没有完成 --refresh-dependencies 的输出:

| 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-dependencies 之后:

| 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

【问题讨论】:

  • 尝试升级到 2.3.4 或至少升级到 2.3.0 以外的版本 - 两个版本之间修复了很多错误
  • 我升级到 2.3.4 仍然遇到同样的问题。

标签: grails dependency-management


【解决方案1】:

我不认为这是对我自己问题的“答案”,但我将其发布在这里作为可能的解决方法,以防其他人遇到此问题。

我能够通过 BuildConfig.groovy 拉入我的 oracle 驱动程序而不是使用 /lib 文件夹来阻止此问题的发生。

我不认为这是一个解决方案的原因是,为了做到这一点,您需要一个可以找到 oracle 驱动程序工件的存储库,并且它不在任何公共存储库中,也不允许由于“吝啬” oracle的一部分。

我的公司有一个我可以使用的私有存储库,它由我们的 CI 服务器共享,并且此解决方案仅适用于有权访问某种私有存储库的人。我在 BuildConfig.groovy 中添加的内容几乎是您所期望的:

runtime "com.oracle:ojdbc6:11.2.0.1.0"

那些由于没有包含 oracle 驱动程序 jar 的存储库而无法使用此解决方案的人仍然需要解决使用 /lib 时出现的问题。

【讨论】:

    【解决方案2】:

    我遇到过类似的问题,有一次它可以正常运行应用程序,但一旦我重新启动它就会抛出“池连接”异常。

    在 BuildConfig.groovy 中添加以下行解决了我的问题。不知道为什么一开始就不见了。

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

    【讨论】:

      【解决方案3】:

      这看起来像是 2.3 中默认使用的新 Aether 依赖管理器的问题。它比 Ivy 快得多,并且通常比 Ivy 更好,但有一些 Ivy 功能​​不受支持。

      我可以通过在BuildConfig.groovy 中将 Aether 更改为 Ivy 来完成这项工作:

      grails.project.dependency.resolver = "ivy"
      

      【讨论】:

      • 不幸的是,这对我没有任何改变。
      • 尝试运行grails compile --refresh-dependencies
      • 我已经这样做了,因为这样做是复制问题的一部分。和以前一样,当运行 grails compile --refresh-dependencies 后立即运行 run-app 时问题不会出现,但任何后续运行 run-app 时都会出现问题,除非 grails compile --refresh-dependencies 再次运行.
      【解决方案4】:

      从这里更改我的BuildConfig 中的行:

      runtime "com.oracle:ojdbc6:11.2.0.1.0"
      

      至此(省略 com.):

      runtime "oracle:ojdbc6:11.2.0.1.0"
      

      为我工作。

      【讨论】:

        猜你喜欢
        • 2011-12-14
        • 2015-10-02
        • 2012-10-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-16
        • 1970-01-01
        • 2022-11-24
        相关资源
        最近更新 更多