You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
I noticed that in MyBatis' auto-configuration, the SqlSessionFactoryBean object is not managed by the Spring IoC container. Instead, it is manually created, and the getObject() method is invoked to obtain the SqlSessionFactory at the end. This SqlSessionFactory object is then managed by the IoC container, rather than the SqlSessionFactoryBean. So, is it incorrect for the SqlSessionFactoryBean object to be managed by the Spring IoC container?
Of course, I still think that using SqlSessionFactoryBean as a listener is too broad in scope for the events it listens to.
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.
The text was updated successfully, but these errors were encountered: