I have a Spring Boot application which has some external dependencies (eg. files outside the project that need to exists in order for the application to start up properly).
One of my beans has a @PostConstruct
method that does the initialization. I would like to exit cleanly and gracefully if the initialization is not successful - for example, the files are not found.
Calling ((ConfigurableApplicationContext)applicationContext).close();
in the @PostConstruct
method results in
java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context
and a chain of other Exceptions. Is there a way to do this properly?
you can't use System.exit(0)
in @PostConstruct
, shutdown will waiting lock of startupShutdownMonitor
, can't exit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With