Is it possible to replace the below code creating applicationcontext and registering a shutdownhook:
ClassPathXmlApplicationContext context
= new ClassPathXmlApplicationContext(configLocation);
context.start();
context.registerShutdownHook();
with try-with-resources contruct, something like:
try (ClassPathXmlApplicationContext context
= new ClassPathXmlApplicationContext(configLocation)) {
context.start();
} catch (Exception e) {
e.printStackTrace();
}
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?