We have an ApplicationRunner
to create an admin user on the first start of a spring boot application.
To create the user, it must connect to an auth server (we use Keycloak
). However, if the service is deployed together with the main application (via docker-compose up -d
) it will take some time until the auth server is available, actually, too long. The ApplicationRunner
will fail with a 502 Bad Gateway
exception, because it is executed before the auth server is up and running.
How can the ApplicationRunner
delay creating the admin until the auth server is up?
Ideally, the ApplicationRunner
should delay everything and provide some information about the "waiting state" during startup. If after e.g. 1 min or so the auth server is not available during startup, the application run should fail.
Notes We are using docker-compose version 3. We are looking for an application level solution, because docker-compose docs state that this should be handled on the application level.