title: How do I terminate a Spring application during startup?
body: <p>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).</p>
  
  <p>One of my beans has a <code>@PostConstruct</code> 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.</p>
  
  <p>Calling <code>((ConfigurableApplicationContext)applicationContext).close();</code> in the <code>@PostConstruct</code> method results in </p>
  
  <pre><code>java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context
  </code></pre>
  
  <p>and a chain of other Exceptions. Is there a way to do this properly?</p>