14

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.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:

<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.

Polyphase29
  • 475
  • 1
  • 4
  • 17
  • https://stackoverflow.com/questions/48096184/oracle-ojdbc8-12-2-0-1-forbidden-by-maven – clevertension Sep 23 '18 at 23:21
  • If you are not using multiple data sources then remove mysql-connector-java, spring-boot-starter-data-mongodb, h2, mongo-java-driver and run mvn clean install to install all jars cleanly as seems some jar corrupted then start.. – kj007 Sep 24 '18 at 02:13

5 Answers5

12

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

Damith
  • 740
  • 4
  • 12
  • 2
    Hm. that seems to work but now I'm being told "Cannot load driver class: oracle.jdbc.driver.OracleDriver" through multiple exceptions being thrown. Any idea? – Polyphase29 Sep 25 '18 at 00:28
  • 1
    Its basically the class is not present in your classpath. The same kind of error is discussed here. please refer https://stackoverflow.com/questions/1074869/find-oracle-jdbc-driver-in-maven-repository – Damith Sep 25 '18 at 05:43
1
    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
Abdullah Imran
  • 259
  • 3
  • 13
1

I have the same probleme Add this dependence to POM.xml file

<dependency>
            <groupId>com.oracle.ojdbc</groupId>
            <artifactId>ojdbc8</artifactId>
            <scope>runtime</scope>
    </dependency>
0

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

mvn clean install

ridvan.yazici
  • 69
  • 1
  • 4
0

Below dependency to POM should work.

<!-- https://mvnrepository.com/artifact/oracle/ojdbc6 -->
        <dependency>
            <groupId>com.oracle.database.jdbc</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0.4</version>
        </dependency>
Aish
  • 1