In my case, the error was valid and it was due to using try with resource
try (ConfigurableApplicationContext cxt = new ClassPathXmlApplicationContext(
"classpath:application-main-config.xml")) {..
}
It auto closes the stream which should not happen if I want to reuse this context in other beans.