I am trying to deploy some microservices over Azure Kubernetes cluster using Helm chart. Some of those services use PostgreSQL DB(Type-1 services) and others use MongoDB(Type-2 services).
Type-1 services are working fine but Type-2 services are not working with following error:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: org.postgresql.Driver
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
... 43 common frames omitted
Caused by: java.lang.IllegalStateException: Cannot load driver class: org.postgresql.Driver
at org.springframework.util.Assert.state(Assert.java:97)
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:242)
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:194)
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:48)
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari.dataSource(DataSourceConfiguration.java:90)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 44 common frames omitted
I don't understand why services that use MongoDB as a database seek Postgres driver, as seen in the error message. The values.yaml
look like this:
type1-service:
imagePullSecrets:
- name: regcred
global:
envVariable:
common:
spring_datasource_url: "jdbc:postgresql://postgres01.some.hostname:5432/jarvis?sslfactory=org.postgresql.ssl.NonValidatingFactory"
spring_datasource_username: "tonystark"
spring_datasource_password: "peter"
kafka_bootstrap_servers: "kafka01.some.hostname:9092"
spring_kafka_bootstrap_servers: "kafka01.some.hostname:9092"
oauth2_defaultSuccessURL: "https://some.web.hostname/"
CLUSTERNAME: "demo.some.aks.hostname"
type2-service:
imagePullSecrets:
- name: regcred
global:
envVariable:
common:
spring_datasource_url: "mongodb://mongo01.some.hostname:27017/?authSource=admin&replicaSet=rs1"
envVariable:
service:
vars:
spring_data_mongodb_database: mydatabase
kafka_topics_query_event: "search_text"
kafka_topics_result_event: "result_name"
spring_data_mongodb_auto-index-creation: false
I am not getting this error when running the same micro-service in local system. Appreciate any help here.