//获取DefaultSingletonBeanRegistry下收集所有单例注册的属性
Field singletonObjects = DefaultSingletonBeanRegistry.class.getDeclaredField("singletonObjects");
//取消语言访问检查
singletonObjects.setAccessible(true);
//获取context下面的BeanFactory
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
从这里向下就看不懂了,为什么要get Factory
Map<String, Object> map = (Map<String, Object>) singletonObjects.get(beanFactory);
map.entrySet().stream().forEach(info->{
System.out.println(info.getKey()+"==="+info.getValue());
});
关于获取DefaultSingletionBeanRegistry的单例属性获取
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
Tomshidi 2022-06-22 10:21关注Map<String, Object> map = (Map<String, Object>) singletonObjects.get(beanFactory);
这一句的意思是:从beanFactory对象中获取属性singletonObjects的值。Field singletonObjects = DefaultSingletonBeanRegistry.class.getDeclaredField("singletonObjects")。这里的singletonObjects只是一个类结构定义,真正获取值需要用具体实例对象去拿,比如传入这里的beanFactory = context.getBeanFactory()这个factory对象。本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报