1. ID and name attribute are the same, the recommended use ID;
2. The ID value requirement is strict, must satisfy the XML naming specification. The ID is unique, and no two <bean> of the same ID is allowed in the configuration file.
3. The name value is more casual and can even start with a number. Two <bean> with the same name are allowed in the configuration file, and the subsequent bean is returned when the instance is returned with Getbean ().
4. If there is no id,name, use the full name of the class as name, such as <bean class= "test. Test, you can use Getbean ("test"). Test ") returns the instance.
5. ID when separated by a semicolon (";"), A Space ("") or a comma (",") can only be used as an identity, name with a semicolon (";"), A Space ("") or a comma (",")
Separate the multiple identities that will be part of the component (equivalent to the role of alias aliases).
Such as:
Name= "1 2 3 4" equivalent to Name= "1,2,3,4" is equivalent to having 1 2 3 4 (4 ) identifiers identifying the current bean
Id= "1 2 3 4" This is equivalent to having a "1 2 3 4" (1 ) identifier identifying the current bean
6. If the ID is configured and name is configured, then two are valid.
7. If there are multiple IDs and the name is not specified, and the instance class is the same, such as:
Code
<bean class= "Com.stamen.BeanLifeCycleImpl"/><bean class= "Com.stamen.BeanLifeCycleImpl"/><bean class= "Com.stamen.BeanLifeCycleImpl"/>
The first bean is obtained through Getbean ("Com.stamen.BeanLifeCycleImpl"),
The second bean is obtained through Getbean ("com.stamen.beanlifecycleimpl#1"),
The third bean is obtained through Getbean ("com.stamen.beanlifecycleimpl#2"), and so on.
8. When annotations and configuration files are present
If the annotations and configuration files are used when the basic class is configured, the annotations and the configuration file are different when the name is not the same, then the two does not conflict and can take effect.
If the annotations and configuration files are used when configuring the base class, the annotations and the configuration file name are the same when the two conflicts, the configuration file takes effect.
If the class is referenced as a reference class and is automatically injected, the annotations and configuration files are configured, and if the name is the same, the configuration file takes effect.
If the class is referred to as a reference class and is automatically injected when annotations and configuration files are configured, if the name is not the same, match the autowired match rule.
Note: Matching rules for autowired 1.ByType 2. ByName
Reference:
Http://blog.csdn.net/qq_22063697/article/details/51912386
Http://www.cnblogs.com/flying607/p/5132293.html
The distinction between the ID and name of <bean> in spring