In Defaultlistablebeanfactory, a hashmap holds the loaded beandefinition information, the HASHMAP definition can be seen in defaultlistablebeanfactory:
Private final map<string, beandefinition> beandefinitionmap = new concurrenthashmap<string, BeanDefinition > ();
The process of registering the parsed beandefinition to the IOC container Beandefinitionmap is done after the load beandefinition completes. Defaultlistablebeanfactory implements the Beandefinitionregistry interface, this registration process is to set the parsed beandefinition to HashMap, One thing to be aware of is the beandefinition of the same name, which needs to be handled according to the allowbeandefinitionoverding configuration.
public void Registerbeandefinition (String beanname, Beandefinition beandefinition) throws beandefinitionstoreexception {assert.hastext (beanname, "Bean name must not being empty"); Assert.notnull (beandefinition, "beandefinition must not being null"); if (beandefinition instanceof abstractbeandefinition) {try {(abstractbeandefinition) Beandefi nition). Validate (); } catch (Beandefinitionvalidationexception ex) {throw new Beandefinitionstoreexception (Beandefi Nition.getresourcedescription (), Beanname, "Validation of bean definition failed", ex); }}//registration process requires synchronization to ensure data consistency synchronized (THIS.BEANDEFINITIONMAP) {//check whether a bean with the same name has been registered, if it exists and does not allow Overwrite throws exception Object oldbeandefinition = This.beanDefinitionMap.get (beanname); if (oldbeandefinition! = null) {if (!this.allowbeandefinitionoverriding) {throw new be AndefinitionstoreexceptIon (Beandefinition.getresourcedescription (), Beanname, "Cannot register bean definition [" + beandefinition + "] for Bean ' + Beanname + ': There is already ["+ Oldbeandefinition +"] bound. "); else {if (this.logger.isInfoEnabled ()) {this.logger.info ("overriding Bean Defi Nition for Beans ' "+ beanname +" ': replacing ["+ Oldbeandefinition +"] with ["+ Beandefinition +"] "); }}} else {//normal registration process, put the name of the bean into Beandefinitionname, and Beanname as Map's key,beandefinition as the value of map This.beanDefinitionNames.add (beanname); This.frozenbeandefinitionnames = null; } this.beanDefinitionMap.put (Beanname, beandefinition); Resetbeandefinition (Beanname); } }
Completing the Beandefinition registration completes the IOC container initialization process, where the entire bean configuration information has been established in defaultlistablebeanfactory, and these beandefinition can already be used by the container. The purpose of the container is to process and maintain this information, which is the basis for the container to establish a dependency reversal.
SPRING-IOC source code Interpretation of 2.3-beandefinition registration