ResetBeanPostProcessorCaches.java 文件源码

java
阅读 28 收藏 0 点赞 0 评论 0

项目:HotswapAgent 作者:
/**
   * Reset all post processors associated with a bean factory.
   *
   * @param beanFactory beanFactory to use
   */
  public static void reset(DefaultListableBeanFactory beanFactory) {
Class<?> c = getReflectionUtilsClassOrNull();
if (c != null) {
    try {
        Method m = c.getDeclaredMethod("clearCache");
        m.invoke(c);
    } catch (Exception version42Failed) {
              try {
                  // spring 4.0.x, 4.1.x without clearCache method, clear manually
                  Field declaredMethodsCache = c.getDeclaredField("declaredMethodsCache");
                  declaredMethodsCache.setAccessible(true);
                  ((Map)declaredMethodsCache.get(null)).clear();

                  Field declaredFieldsCache = c.getDeclaredField("declaredFieldsCache");
                  declaredFieldsCache.setAccessible(true);
                  ((Map)declaredFieldsCache.get(null)).clear();

              } catch (Exception version40Failed) {
                  LOGGER.debug("Failed to clear internal method/field cache, it's normal with spring 4.1x or lower", version40Failed);
              }
    }
    LOGGER.trace("Cleared Spring 4.2+ internal method/field cache.");
}
      for (BeanPostProcessor bpp : beanFactory.getBeanPostProcessors()) {
          if (bpp instanceof AutowiredAnnotationBeanPostProcessor) {
              resetAutowiredAnnotationBeanPostProcessorCache((AutowiredAnnotationBeanPostProcessor)bpp);
          } else if (bpp instanceof InitDestroyAnnotationBeanPostProcessor) {
              resetInitDestroyAnnotationBeanPostProcessorCache((InitDestroyAnnotationBeanPostProcessor)bpp);
          }
      }
  }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号