有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

刷新应用程序上下文时的JavaSpring生命周期

我一直在寻找描述Spring如何在内部管理应用程序上下文刷新的文档

      ApplicationContext context = new ClassPathXmlApplicationContext("portalResetWebApplicationContext.xml");
    ((ConfigurableApplicationContext) context).refresh();

我想知道的是,以前被实例化为singleton(默认情况下)的所有bean是否都发生了什么

问候


共 (1) 个答案

  1. # 1 楼答案

    根据javadoc

    As this is a startup method, it should destroy already created singletons if it fails, to avoid dangling resources. In other words, after invocation of that method, either all or no singletons at all should be instantiated.

    所以我建议你给一个类添加一个静态计数器,看看每个实例创建了多少个实例