Issue
What I am looking for is some suggestions on this behavior: Spring boot app(Considered as a microservice) should come up, irrespective of Db status.
Why I am doing this? Based on my understanding of the microservice all services should be independent of each other.
I am using Spring boot with JPA (org.springframework.boot' version '2.5.7'). I am able to achieve this using the below configuration
spring:
datasource:
driverClassName: org.postgresql.Driver
url: jdbc:postgresql://localhost:5433/xxx?createDatabaseIfNotExist=true&characterEncoding=utf8&enabledTLSProtocols=TLSv1.2&useSSL=false
username: xx
password: xx
continueOnError: true
initialize: false
initialSize: 0
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 5000
minIdle: 0
jpa:
show-sql: true
hibernate:
naming_strategy: org.hibernate.cfg.DefaultNamingStrategy
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
hbm2ddl:
auto: none
temp:
use_jdbc_metadata_defaults: false
But now the issue is I have to make hbm2ddl.auto none. Due to this, I am losing update schema functionalists which is one of the very essential functionality.
Requirement: case 1. Service should be up and running irrespective of DB status case 2. Jpa/Hibernate should update the database schema by comparing the existing schema with the entity mappings and generate the appropriate schema migration scripts (hbm2ddl.auto: update)
Can we achieve both? If yes how? or Do I have to compromise with one? If I am going with only "case 1" do I have to rely on running schema updates manually or is there any other way?
thanks in advance
Solution
As mentioned in the comment you can exclude org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
if you wish for spring boot to ignore the status of the data source (link on how to do that). In order to still have the schema auto-generated/controlled outside of your actual db you could use something like liquibase, which is used a lot in production environments.
Answered By - mrkachariker
Answer Checked By - Marie Seifert (JavaFixing Admin)