I have quite a complex Spring Boot application (including Spring MVC and Security), which among other things requires a database configuration (url, username and password). The requirement is to let end-user configure the DB with the help of the application itself, like the following:
- User starts the application, which has no DB configuration yet
- Application notices the absence of DB configuration and presents user with configuration screen
- User enters url and credentials
- Application starts using this DB
The obvious problem is that I cannot create any beans that require a DataSource
which requires DB configuration until that configuration is known.
Is there any way to postpone the initialisation of the majority of the application's beans until first configuration step is performed?
-- Update --
Several of application's beans initialise their state from the DB in their @PostConsutrct
methods. So I either need to really delay their creation or have a method of refreshing (potentially) all beans in the application context after configuration is provided.