I have a SpringBoot application that will fail to start up when the database it is using is not up since the datasource bean will fail to initialize. I want for my application to not start before my db is up in order to avoid this failure.
To mention that this app is running in Kubernetes so one option would be to use an init-container. I would want though to have that logic inside the application itself.
First of all, is that a bad idea and I should stick with init-containers?
If it is not a bad idea what is usually the best approach for this. I was looking at Spring Retry and one possible solution seems to be to have retry logic in the @Bean datasource initialization method. Does that have any possible drawbacks? Is there a better way?