+-
SpringBoot遇到一个诡异的bug,每次停止项目的时候报错,求大佬指点
Disconnected from the target VM, address: '127.0.0.1:49987', transport: 'socket'
2021-05-22 22:36:34.077  INFO 38235 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2021-05-22 22:36:35.449  INFO 38235 --- [tor-Framework-0] o.a.c.f.imps.CuratorFrameworkImpl        : backgroundOperationsLoop exiting
2021-05-22 22:36:35.490  INFO 38235 --- [ain-EventThread] org.apache.zookeeper.ClientCnxn          : EventThread shut down for session: 0x1000000a7da6620
2021-05-22 22:36:35.490  INFO 38235 --- [extShutdownHook] org.apache.zookeeper.ZooKeeper           : Session: 0x1000000a7da6620 closed
2021-05-22 22:36:35.493  INFO 38235 --- [extShutdownHook] com.alibaba.druid.pool.DruidDataSource   : {dataSource-3} closing ...
2021-05-22 22:36:35.506  INFO 38235 --- [extShutdownHook] com.alibaba.druid.pool.DruidDataSource   : {dataSource-3} closed
2021-05-22 22:36:35.506  INFO 38235 --- [extShutdownHook] com.alibaba.druid.pool.DruidDataSource   : {dataSource-4} closing ...
2021-05-22 22:36:35.510  INFO 38235 --- [extShutdownHook] com.alibaba.druid.pool.DruidDataSource   : {dataSource-4} closed
2021-05-22 22:36:35.512  INFO 38235 --- [extShutdownHook] com.alibaba.druid.pool.DruidDataSource   : {dataSource-4} closing ...
2021-05-22 22:36:35.512  INFO 38235 --- [extShutdownHook] com.alibaba.druid.pool.DruidDataSource   : {dataSource-3} closing ...
2021-05-22 22:36:35.512  INFO 38235 --- [extShutdownHook] com.alibaba.druid.pool.DruidDataSource   : {dataSource-2} closing ...
2021-05-22 22:36:35.513  INFO 38235 --- [extShutdownHook] com.alibaba.druid.pool.DruidDataSource   : {dataSource-2} closed
2021-05-22 22:36:35.513  INFO 38235 --- [extShutdownHook] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} closing ...
2021-05-22 22:36:35.514  INFO 38235 --- [extShutdownHook] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} closed
2021-05-22 22:36:35.518  WARN 38235 --- [extShutdownHook] s.c.a.AnnotationConfigApplicationContext : Exception thrown from ApplicationListener handling ContextClosedEvent

org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'sqlSessionFactoryOpen': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:208)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207)
    at org.springframework.context.event.AbstractApplicationEventMulticaster.retrieveApplicationListeners(AbstractApplicationEventMulticaster.java:245)
    at org.springframework.context.event.AbstractApplicationEventMulticaster.getApplicationListeners(AbstractApplicationEventMulticaster.java:197)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:134)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:403)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:409)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:360)
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1012)
    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:978)
    at org.springframework.cloud.context.named.NamedContextFactory.destroy(NamedContextFactory.java:92)
    at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:258)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:571)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:543)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:1075)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:504)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:1068)
    at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1060)
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1029)
    at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:948)

2021-05-22 22:36:35.519  WARN 38235 --- [extShutdownHook] s.c.a.AnnotationConfigApplicationContext : Exception thrown from ApplicationListener handling ContextClosedEvent

Process finished with exit code 130 (interrupted by signal 2: SIGINT)

看着应该是,sqlSessionFactoryOpen 创建的过程中就停止了

是不是还没完全启动成功就点停止了? 有比较耗时的创建bean,比如连接池初始化或者rpc初始化之类的网络操作一直没完成,这个时候停止了

应该是在代码的某处对ApplicationContext做了关闭动作,导致调用了DefaultSingletonBeanRegistry#destroySingletons,singletonsCurrentlyInDestruction设置为true。然后在getSingleton的时候被检测到,抛出了异常。

@see AbstractApplicationContext#close()
@see AbstractApplicationContext#destroyBeans()

在关闭的时候调用了BeanFactory#getBean()操作,应该检查下destroy相关方法的准确性。