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
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.
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.
"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.
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.
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>
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 :).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With