} else {
try {
factory.destroyBean(name, ctx);
} catch (Exception e) {
log.warn("Context destroy failed for: {}", name, e);
ctx.destroy();
} finally {
if (factory.containsSingleton(name)) {
log.debug("Singleton still exists, trying another destroy method");
((DefaultListableBeanFactory) factory).destroySingleton(name);
}