Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot Hikari can't find DriverClassName

I have a spring boot project,It run just fine when I execute via eclipse Project > Run as > spring boot app

but when I build the project and execute it using java -jar myproject.jar or run it using mvn spring-boot:run it throw this error

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

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

Action:

Update your application's configuration

my sql server connector dependency

<dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
        <version>6.4.0.jre8</version>
        <scope>test</scope>
</dependency>

and here my application.properties

spring.datasource.url=jdbc:sqlserver://mydb;databaseName=HTSdb
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.jpa.show-sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect

it looks my app can't find the sqlserver driver but it is already in project classpath,any suggestion? thanks in advance

like image 806
Gusti Arya Avatar asked Jul 18 '18 05:07

Gusti Arya


People also ask

How do I get Hikari DataSource in spring boot?

Configuring Hikari With Spring Boot 1. x uses the Tomcat JDBC Connection Pool by default. As soon as we include spring-boot-starter-data-jpa into our pom. xml, we'll transitively include a dependency to the Tomcat JDBC implementation. During runtime, Spring Boot will then create a Tomcat DataSource for us to use.

What is spring DataSource Hikari maximum pool size?

spring.datasource.hikari.maximum-pool-size=50. Specifies number of database connections between database and application. This property controls the maximum size that the pool is allowed to reach, including both idle and in-use connections. spring.datasource.hikari.connection-timeout=60000.

What is Hikari connection pool?

"HikariCP is solid high-performance JDBC connection pool. A connection pool is a cache of database connections maintained so that the connections can be reused when future requests to the database are required. Connection pools may significantly reduce the overall resource usage." - You can find out more here.

What is the use of Hikari in spring boot?

HikariCP is a reliable, high-performance JDBC connection pool. It is much faster, lightweight and have better performance as compare to other connection pool API. Because of all these compelling reasons, HikariCP is now the default pool implementation in Spring Boot 2.


2 Answers

I think the issue is with dependency scope which is set as test.

Scope test indicates that dependency isn't required at standard runtime of application and should only be used for purpose of test runs only!

Usually database connectors dependency are set with runtime scope.

 <dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>mssql-jdbc</artifactId>
    <version>6.4.0.jre8</version>
    <scope>runtime</scope>
 </dependency>
like image 89
vb.stack Avatar answered Oct 20 '22 01:10

vb.stack


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

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

Action:

Update your application's configuration

Just had the same error, in my case with "org.postgresql.Driver". Gues what was the issue? an empty space after "org.postgresql.Driver " by mistake.

So, be aware about that ' ' invisible empty space :).

like image 39
Iosif Mocanu Avatar answered Oct 20 '22 01:10

Iosif Mocanu