title: Spring ClasPathXmlApplicationContext registerShutDownHook vs using try-with-resources
body: <p>Is it possible to replace the below code creating applicationcontext and registering a shutdownhook:</p>
  
  <pre><code>ClassPathXmlApplicationContext context 
     = new ClassPathXmlApplicationContext(configLocation);
  context.start();
  context.registerShutdownHook();
  </code></pre>
  
  <p>with try-with-resources contruct, something like:</p>
  
  <pre><code>try (ClassPathXmlApplicationContext context 
         = new ClassPathXmlApplicationContext(configLocation)) {
          context.start();
      } catch (Exception e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>I want to be able to catch any exceptions raised while loading app-context, so wondering if using try-with-resources will be fine and sufficient (ApplicationContext is AutoCloseable). Are both the above mentioned code snippets equivalent? </p>