user12016539
user12016539

Reputation:

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

I am trying to run the spring boot application not able to access H2 database

   spring.datasource.initialization-mode=embedded
    spring.datasource.url=jdbc:h2:mem:bitsapi;MODE=Oracle;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
    spring.datasource.username=sa
    spring.datasource.password=

these how my pom.xml i have added dependency's

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
</dependency>

<dependency>
    <groupId>com.zaxxer</groupId>
    <artifactId>HikariCP</artifactId>
    <version>2.7.9</version>
    <scope>compile</scope>
</dependency>

when i run the the application am getting failed to bind properties

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-13 12:01:39,685 [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter 

***************************
APPLICATION FAILED TO START
***************************

Description:

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

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

Action:

Update your application's configuration

Upvotes: 6

Views: 12000

Answers (3)

kanakangi
kanakangi

Reputation: 81

Please check the spelling and case of the letters - upper case or lower case. After googling all over the world , I found that I typed 'datasource' instead of 'dataSource' in my application.properties. I am new to IntelliJ and don't know why it is not giving any auto-suggestions.

Upvotes: 0

Sanjay Tank
Sanjay Tank

Reputation: 113

I was getting above error,
when trying to bring-up my spring-boot application in intellij.
The mistake I was making was
After changing in "build.gradle" file,
(ie adding runtimeOnly('com.h2database:h2'))
I did NOT do the "Reload gradle project",
that's why above error was coming.
Once completed "Reload gradle project", above error was gone.

Upvotes: 3

rieckpil
rieckpil

Reputation: 12051

I guess you use the Spring Boot Starter JPA. This dependency already comes which the Hikari Connection Pooling dependency and I would suggest to remove it from your pom.xml and let Spring Boot manage the versions.

Once you removed the manual import of the Hikari CP, make sure to have runtime scope of your H2:

<dependency>
  <groupId>com.h2database</groupId>
  <artifactId>h2</artifactId>
  <scope>runtime</scope>
</dependency>

Short explanation of what the runtime scope is doing:

runtime is useful for dependencies required for unit tests and at runtime, but not at compile time. This may typically be dynamically loaded code, such as JDBC drivers, which are not directly referenced in the program code (Maven : what is the "runtime" scope purpose?)

Upvotes: 9

Related Questions