title: Close spring on initialization
body: <p>So I have a Spring app running on Tomcat. While deploying initialization I sometimes may run into some errors (i.e. that some JDNI value is not found or that the app is not able to connect to some service). So when this happen I throw and exception and catch it in the @Configuration file. In the catch block I try to close the app with a System.exit(-1). But it doesn't seem to be the right way to do it. Cause Intellij is no capable or turning off the server, I even have seen that resources are not released till server is OFF.</p>
  
  <p>I have also tried:</p>
  
  <pre><code>@Autowired
  public ApplicationContext application context
  @Bean
  public IServerDataCache serverDataCache() {
      try {
          return new ServerDataCache(args);
      } catch(InitializationError initializationError) {
          log.error("Unable to load configuration for Server Data Cache. Closing application.");
          System.exit(1); OR SpringApplication.exit(applicationContext)
      }
      return null;
  }
  </code></pre>
  
  <p>Both  System.exit(1); OR SpringApplication.exit(applicationContext) seem to have the same effect. Any idea of a better way to enforce application finalization.</p>
  
  <p>BTW it is a spring boot application.</p>