Iam trying to dockerizing springboot microservice application but getting below error while deploying. Below providing all configuration details. Please help to resolve by providing any hint.
Same working fine on idea and able to test using postman
Failed to instantiate com.zaxxer.hikari.HikariDataSource: Factory method 'dataSource'exception with message: Failed to determine suitable driver class
application.propertie
spring.datasource.url= jdbc:sqlserver://localhost:1433;encrypt=true;trustServerCertificate=true;databaseName=The_Read
spring.datasource.username= The_read
spring.datasource.password= Read@123456
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
gradle dependencies
dependencies {
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
implementation('org.springframework.boot:spring-boot-starter-security:3.0.1')
implementation 'org.projectlombok:lombok:1.18.24'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
annotationProcessor 'org.projectlombok:lombok'
compileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
testCompileOnly 'org.projectlombok:lombok'
implementation 'io.swagger.core.v3:swagger-models:2.2.7'
implementation 'io.swagger.core.v3:swagger-annotations:2.2.6'
implementation 'io.swagger:swagger-annotations:1.6.8'
// https://mvnrepository.com/artifact/org.springframework.security.oauth/spring-security-oauth2
implementation("org.springframework.security.oauth:spring-security-oauth2:2.5.2.RELEASE")
//implementation("org.springframework.security:spring-security-oauth2-jose:5.3.8.RELEASE")
implementation("org.springframework.security:spring-security-oauth2-jose:5.7.3")
// https://mvnrepository.com/artifact/com.auth0/java-jwt
implementation group: ‘com.auth0’, name: ‘java-jwt’, version: ‘4.2.2’
// https://mvnrepository.com/artifact/org.springframework.security/spring-security-core
implementation group: ‘org.springframework.security’, name: ‘spring-security-core’, version: ‘6.0.1’
implementation group: ‘org.springframework.security’, name: ‘spring-security-oauth2-resource-server’, version: ‘5.1.6.RELEASE’
//Thanks for using https://jar-download.com
// https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc
implementation("com.microsoft.sqlserver:mssql-jdbc:11.2.3.jre18")
// https://mvnrepository.com/artifact/javax.annotation/javax.annotation-api
implementation("javax.annotation:javax.annotation-api:1.3.2")
implementation("org.springframework.security:spring-security-oauth2-resource-server:5.1.0.RELEASE")
annotationProcessor "org.projectlombok:lombok:1.18.8"
testAnnotationProcessor("org.projectlombok:lombok:1.18.8")
// https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt
implementation("io.jsonwebtoken:jjwt:0.9.1")
// https://mvnrepository.com/artifact/javax.validation/validation-api
implementation("javax.validation:validation-api:2.0.1.Final")
implementation("javax.xml.bind:jaxb-api:2.3.1")
implementation("org.apache.commons:commons-lang3:3.0")
}
Log stacktrace
2023-01-25 02:07:10 20:37:10.777 [main] WARN org.springframework.context.annotation.AnnotationConfigApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception with message: Failed to determine a suitable driver class
2023-01-25 02:07:10 20:37:10.782 [main] ERROR org.springframework.boot.SpringApplication – Application run failed
2023-01-25 02:07:10 org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration’: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name ‘dataSource’ defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method ‘dataSource’ threw exception with message: Failed to determine a suitable driver class
2023-01-25 02:07:10 at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:798)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:245)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1344)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1188)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:561)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:415)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1324)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1161)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:561)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
2023-01-25 02:07:10 at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1130)
2023-01-25 02:07:10 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:905)
2023-01-25 02:07:10 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:584)
2023-01-25 02:07:10 at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730)
2023-01-25 02:07:10 at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:432)
2023-01-25 02:07:10 at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
2023-01-25 02:07:10 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302)
2023-01-25 02:07:10 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1291)
2023-01-25 02:07:10 at SecurityServiceApplication.main(SecurityServiceApplication.java:9)
2023-01-25 02:07:10 Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘dataSource’ defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method ‘dataSource’ threw exception with message: Failed to determine a suitable driver class
2023-01-25 02:07:10 at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:657)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:645)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1324)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1161)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:561)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
2023-01-25 02:07:10 at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:254)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1405)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1325)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:885)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:789)
2023-01-25 02:07:10 … 27 common frames omitted
2023-01-25 02:07:10 Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method ‘dataSource’ threw exception with message: Failed to determine a suitable driver class
2023-01-25 02:07:10 at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:171)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
2023-01-25 02:07:10 … 41 common frames omitted
2023-01-25 02:07:10 Caused by: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2023-01-25 02:07:10 at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:182)
2023-01-25 02:07:10 at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:123)
2023-01-25 02:07:10 at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:48)
2023-01-25 02:07:10 at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari.dataSource(DataSourceConfiguration.java:90)
2023-01-25 02:07:10 at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
2023-01-25 02:07:10 at java.base/java.lang.reflect.Method.invoke(Method.java:577)
2023-01-25 02:07:10 at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:139)
2023-01-25 02:07:10 … 42 common frames omitted
Please help
2
Answers
You seem to be mixing spring-boot 3 starters with spring-boot 2 dependencies (for instance security 5). Don’t do that or you’ll get incompatibility issues (like the one you’re probably hitting).
Use spring-boot Graddle plug-in and specify a dependency version only when it is not managed by boot.
Always make sure the versions of java and the spring boot version are compatible. The following checkpoints will also help you identify any dependency or configuration that is missing.
Check if the following dependencies(.pom/.gradle) are added:
spring-boot-starter-data-jpa
mysql-connector-j
Check if the proper configurations(
application.properties
) are given:spring.datasource.url=jdbc:mysql://localhost:3306/testdb
spring.datasource.username=dbusername
spring.datasource.password=dbpassword
Make sure the database(
testdb
) is created before starting the appMake sure the DB is up and running before starting the app