-1

I have the need for starting the application without initialisation of db, when it's needed that time only it should make configuration of db, connection pool and fetch the data. If the db is down, the application start-up should not fail and whenever the db is up, it should serve the request without restart of the application. What are the ways in which I can make this possible in spring boot application?

  • 1
    Does any error message appear in the log upon failure that might be helpful for troubleshooting purposes? Also, if that’s actually how you have “initialization” spelled (“inirialisation”), then you will need to correct it for it to work. – Woodchuck May 13 '23 at 23:53
  • Errors differs in the each try. but requirement to be achieved is service and apis should be up even if the db is down. if the db is again up the app should serve the request without the restart of the application - kindly read this issue also which has same requirement - https://stackoverflow.com/questions/71584082/spring-boot-jpa-start-without-database-and-connect-later – Adhiyaman Muthu May 14 '23 at 19:11
  • The fact that the error is non-deterministic seems peculiar, though that may in itself be some type of clue into the nature of the issue. – Woodchuck May 14 '23 at 22:20

1 Answers1

0

You can exclude the auto-configuration of the datasource in the main application class. Like this:

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})

Please note: this should be done for testing purpose only. After database is available the above exclusion should be removed and the application should be restartet. The Spring Boot auto-configuration is very complex and is the best way to configure all parts of the software. Doing it manually is a wrong design decision.

Mar-Z
  • 2,660
  • 2
  • 4
  • 16
  • Thanks for the suggestion, i have tried them in the project but the requirement is different. The service and apis should be up even if the db is down. if the db is again up the app should serve the requests without the restart of the application - kindly read this issue also which has same requirement - https://stackoverflow.com/questions/71584082/spring-boot-jpa-start-without-database-and-connect-later – Adhiyaman Muthu May 14 '23 at 19:12
  • What else should the application do without access to the model? If it is a static website then probably it will be better to have two separate applications. Microservice architecture instead of monolith. – Mar-Z May 15 '23 at 07:57