spring 无法在 HikariConfig 类加载器或线程上下文中加载驱动程序类 oracle.jdbc.OracleDriver

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52470736/
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-08 01:38:51  来源:igfitidea点击:

Failed to load driver class oracle.jdbc.OracleDriver in either of HikariConfig class loader or Thread context

springoracle

提问by Polyphase29

I'm working with Spring for the first time and trying to set it up so that my code can access an Oracle database. I have the following configuration in my application.properties:

我第一次使用 Spring 并尝试对其进行设置,以便我的代码可以访问 Oracle 数据库。我的 application.properties 中有以下配置:

spring.datasource.url=jdbc:oracle:thin:@140.192.30.237:1521:def
    spring.datasource.username=<username>
    spring.datasource.password=<password>
    spring.datasource.driver.class-name=oracle.jdbc.driver.OracleDriver

My pom.xml contains the following dependencies:

我的 pom.xml 包含以下依赖项:

<dependencies>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>com.oracle.jdbc</groupId>
        <artifactId>ojdbc8</artifactId>
        <version>12.2.0.1</version>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongo-java-driver</artifactId>
        <version>LATEST</version>
    </dependency>
    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>LATEST</version>
    </dependency>
    <dependency>
        <groupId>javax.json</groupId>
        <artifactId>javax.json-api</artifactId>
        <version>1.0</version>
    </dependency>
</dependencies>

Yet I get the following error and am not sure how to solve it, I"ve found similar ones from searching but none that have solved my problem:

但是我收到以下错误并且不知道如何解决它,我从搜索中找到了类似的错误,但没有一个解决了我的问题:

Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:

    Property: driverclassname
    Value: oracle.jdbc.OracleDriver
    Origin: "driverClassName" from property source "source"
    Reason: Failed to load driver class oracle.jdbc.OracleDriver in either of HikariConfig class loader or Thread context classloader

Action:

Update your application's configuration

Thanks for any tips to solve this.

感谢您提供解决此问题的任何提示。

回答by Damith

As its mentioned in your error the problem is with your configuration. Following line,

正如您在错误中提到的,问题出在您的配置上。以下线路,

spring.datasource.driver.class-name=oracle.jdbc.driver.OracleDriver

should change as,

应该改变为,

spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver

Note that its not driver.class-name, instead its driver-class-name

请注意,它不是driver.class-name,而是它的driver-class-name

回答by abdullah imran

    Add below dependency and repository in the pom

    <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0.3</version>
        </dependency>

    <repositories>
        <repository>
            <id>codelds</id>
            <url>https://code.lds.org/nexus/content/groups/main-repo</url>
        </repository>
       </repositories>


Also add the following properties in the application.properties

 spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
    spring.datasource.url=jdbc:oracle:thin:@localhost:1521:xe(SID)
    spring.datasource.username=system
    spring.datasource.password=pw

回答by ridvan.yazici

Try on the project directory pom.xml file in in command promt or your ide.

在命令提示符或您的 ide 中尝试项目目录 pom.xml 文件。

mvn clean install

mvn 全新安装