Register hook to close application context on JVM shutdown