Groovy/Grails 无法加载 oracle.jdbc.driver.OracleDriver

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11314664/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 00:56:40  来源:igfitidea点击:

Groovy/Grails cannot load oracle.jdbc.driver.OracleDriver

oraclegrailsgroovy

提问by Ryan Flood

I am trying to test a grails app connecting to a sql server, for now, I am using one of my own. This is my datasource.groovy

我正在尝试测试连接到 sql server 的 grails 应用程序,现在,我正在使用我自己的应用程序。这是我的 datasource.groovy

    dataSource {
        configClass = GrailsAnnotationConfiguration.class
        pooled = true
        driverClassName = "oracle.jdbc.driver.OracleDriver"
        dialect = "org.hibernate.dialect.Oracle10gDialect"
        dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
        url = "jdbc:oracle:thin:@127.0.0.1:1521/xe"
        username = "blah"
        password = "blah"
        properties {
            validationQuery="select 1 from dual"
            testWhileIdle=true
            timeBetweenEvictionRunsMillis=60000
        }
    }

I have borrowed this code from a different app, just changing the url and user/password. The other app runs fine, but my app throws a long exception, which boils down to this

我从另一个应用程序中借用了此代码,只是更改了 url 和用户/密码。另一个应用程序运行良好,但我的应用程序抛出了一个很长的异常,归结为这个

Caused by SQLNestedException: Cannot load JDBC driver class 'oracle.jdbc.driver.OracleDriver'
stack trace
Caused by ClassNotFoundException: oracle.jdbc.driver.OracleDriver

I have copied ojdbc6.jar into my app lib/ but I am afraid I am lost on what to do next.

我已将 ojdbc6.jar 复制到我的应用程序 lib/ 中,但恐怕我不知道下一步该做什么。

EDITI have updated oracle.jdbc.driver.OracleDriverto oracle.jdbc.OracleDriver, but no progress

编辑我已更新oracle.jdbc.driver.OracleDriveroracle.jdbc.OracleDriver,但没有进展

回答by Burt Beckwith

Run

grails compile --refresh-dependencies

when you add a jar to the lib directory so Grails adds it to the classpath. This is a new requirement in 2.0+

当您将 jar 添加到 lib 目录时,Grails 会将其添加到类路径中。这是 2.0+ 的新要求

Unrelated - you can remove

无关 - 您可以删除

configClass = GrailsAnnotationConfiguration.class

since that's the default now

因为这是现在的默认设置

回答by tim_yates

Shouldn't the class be:

班级不应该是:

driverClassName = "oracle.jdbc.OracleDriver"

I believe the other one was deprecated

我相信另一个已被弃用

回答by Ryan Flood

So, turns out the problem was what @tim_yates suggested. The problem that I had since then was that even though I was refreshing the dependencies, as @burt said, but I had never re-loaded the config files.

所以,事实证明问题出在@tim_yates 的建议上。从那时起我遇到的问题是,尽管我正在刷新依赖项,正如@burt 所说,但我从未重新加载配置文件。

I just ran grails cleanthen grails compile --refresh-dependenciesand voila, problem solved. Thanks to @burt and @tim_yates for helping me out

grails clean然后我就跑了grails compile --refresh-dependencies,瞧,问题解决了。感谢@burt 和@tim_yates 帮助我