Name of Bean in spring
1, each bean can have an id attribute, and according to the ID in the IOC container to find the bean, the id attribute value must be unique in the IOC container;
2, you can not specify the id attribute, only specify the fully qualified class name, such as:
<class= "Com.zyh.spring3.hello.StaticBeanFactory"></Bean >
The bean needs to be obtained through interface Getbean (Class<t> requiredtype).
Throw exception if the bean cannot be found: nosuchbeandefinitionexception
Throw exceptions if there are more than one bean of that type: nouniquebeandefinitionexception
3, if you do not specify the ID, only specify name, then name is the bean identifier, and need to be unique in the container;
4. Specify both the name and the ID, at which point the ID is an identifier, and name is the Bean alias, both of which can find the target bean;
5, you can specify more than one name, can be separated by semicolons (";"), A Space ("") or a comma (","), if no ID is specified, then the first name is an identifier, the rest is an alias, if the id attribute is specified, the ID is an identifier, all names are aliases. Such as:
< bean name = "alias1 alias2;alias3,alias4" ID = "Hello1" class = "Com.zyh.spring3.hello.HelloWorld" > < constructor-arg index = "0" value = "Rod" ></ constructor-arg > </ bean >
At this point, Hello1 is an identifier, and Alias1,alias2,alias3,alias4 is an alias, which can be used as the bean's key value;
6, you can use the <alias> tag to specify aliases, aliases must also be unique in the IOC container, such as:
<name= "Bean" class= "Com.zyh.spring3.hello.HelloWorld"/ > <alias= "ALIAS1" name= "Bean" /> <alias= "Alias2" name= "Bean" />
Spring Framework5.0 Learning (4)--bean named ID and name difference