Spring Core Framework - Where are the beans hold?

大憨熊 提交于 2020-06-25 09:48:06

问题


I am a junior Java developer and I am reading the spring documentation from spring.io. I read that every bean that gets registered in the *.xml file that spring uses to resolve dependencies is declared using <bean> </bean> tags.

My question is: In which data structure are the beans hold after the xml file is read and the beans are instantiated(created)?

Thank you


回答1:


Although you should not be worried much about the internal structures if you are just beginning to learn Spring but for the sake of knowledge in almost all cases the underlying class is DefaultSingletonBeanRegistry and as you can see by going through the source code here it maintains a ConcurrentHashMap of singleton objects. Also there are similar other map object for other information being stored.

private final Map<String, Object> singletonObjects = new ConcurrentHashMap<String, Object>(64);



回答2:


You can think of it as a Map where the keys are bean ids and the values are actual Objects.



来源:https://stackoverflow.com/questions/25565706/spring-core-framework-where-are-the-beans-hold

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!