问题
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