Spring boot 无法加载驱动类:oracle.jdbc.OracleDrive

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

Spring boot Cannot load driver class: oracle.jdbc.OracleDrive

oraclespring-bootdriver

提问by kotygoroshko

I have driver class in class-path in my jar:

我的 jar 中的类路径中有驱动程序类:

2015-06-18 12:21:40.290 INFO 9453 --- [ main] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: ..... jar:file:/{projecthome}/rest-test/target/rest-test-0.1.0.jar!/lib/ojdbc6-11.2.0.3.0.jar!/]

2015-06-18 12:21:40.290 INFO 9453 --- [ main] .blClasspathLoggingApplicationListener :应用程序无法以类路径启动:..... jar:file:/{projecthome}/rest-test/target/rest- test-0.1.0.jar!/lib/ojdbc6-11.2.0.3.0.jar!/]

I got exception:

我有例外:

Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: oracle.jdbc.OracleDrive

My pom:

我的pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.springframework</groupId>
    <artifactId>rest-test</artifactId>
    <version>0.1.0</version>
    <packaging>jar</packaging>

    <properties>        
        <start-class>hello.Application</start-class>
        <java.version>1.8</java.version>
    </properties>


    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.4.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-dbcp</artifactId>
            <version>${tomcat.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>                
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0.3.0</version>
            <scope>compile</scope>
        </dependency>                
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>
    <name>rest-test</name>
</project>

回答by Naveen Kocherla

Download ojdbc6.jar from Oracle website or if you install oracle11g in your local system you can find ojdbc in jdbc/lib folder.

从 Oracle 网站下载 ojdbc6.jar,或者如果您在本地系统中安装 oracle11g,您可以在 jdbc/lib 文件夹中找到 ojdbc。

Add that ojdbc.jar right click --> build path--> configure build path--> Add external jars--> your local machine ojdbc path -->ok.

添加ojdbc.jar 右键--> 构建路径--> 配置构建路径--> 添加外部jar--> 您的本地机器ojdbc 路径--> 确定。

It worked in my case.

它在我的情况下有效。

回答by Santosh Reddy

step 1:You POM.xml file should be

第 1 步:你的 POM.xml 文件应该是

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

Step 2:Download the ojdbc6 driver from oracle website and keep it in your local machine.

第二步:从oracle官网下载ojdbc6驱动,保存在本地。

step 3:Run maven below command.Dfile is the location where i kept my jar file downloaded from oracle website

第 3 步:在命令下运行 maven。Dfile 是我保存从 oracle 网站下载的 jar 文件的位置

mvn install:install-file -Dfile=C:\Users\santosh\.m2\repository\com\oracle\ojdbc6\11.2.0\ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar

mvn install:install-file -Dfile=C:\Users\santosh\.m2\repository\com\oracle\ojdbc6\11.2.0\ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar

After running maven command it should create ojdbc6-11.2.0 in your maven repository.After that your problem should be fixed.

运行 maven 命令后,它应该在你的 maven 存储库中创建 ojdbc6-11.2.0。之后你的问题应该得到修复。

回答by Tom Chamberlain

Make sure that in your IDE you click maven reimport if it is not reimporting automatically (i.e. IntelliJ: right click project, Maven, Reimport), as it will compile fine without being on the classpath, but fail at runtime

确保在您的 IDE 中单击 maven reimport,如果它没有自动重新导入(即 IntelliJ:右键单击项目,Maven,重新导入),因为它可以在没有类路径的情况下正常编译,但在运行时会失败