Description
When there are multiple ApplicationContexts in Spring, ContextClosedEvent may be broadcasted multiple times. For example, FeignContext, since SqlSessionFactory listens to all ApplicationEvents, if the application is closed, when SqlSessionFactoryBean is destroyed first, and FeignContext is destroyed later, ContextClosedEvent will be broadcasted. When Spring tries to get the listener, BeanCreationNotAllowedException is thrown because SqlSessionFactoryBean's singleton bean has been destroyed and it indicates that singletons are currently being destroyed (singletonsCurrentlyInDestruction=true).
From the implementation of SqlSessionFactory, I think that it does not need to listen to all ApplicationEvents, and only needs to listen to ContextRefreshedEvent.