I. Overall structure
Two. Detailed
1.spring <alias > tags
When defining a bean, in addition to using the id attribute to specify a name, to provide multiple names, you can use the alias tag to specify. While all of these names point to the same bean, it can be useful to provide aliases in some cases, such as to make it easier for each component of the application to reference common components.
However, it is not always appropriate to specify all aliases when defining a bean. Sometimes we expect to introduce aliases in the current location for beans that are defined elsewhere. In the XML configuration file, a separate <alias/> element is used to complete the definition of the bean alias. Such as:
Equivalence situation
A javabean is defined in the configuration file.
<bean id= "Some" class= "Src.com.Some"/>
I'm going to add an alias to this javabean to make it easier for different objects to invoke. We can write it this way:
<bean id= "Some" class= "Src.com.Some"/>
<alias name= "Some" alias= "Somejava,onebean,twobean"/>
Or it is specified with the Name property, such as:
<bean id= "Some" name= "Onebean,twobean,threebean" class= "Src.com.Some"/>
A bit more trouble to use
Consider a more specific example in which component a defines a datasource bean named Componenta-datasource in the XML configuration file. But component B wants to refer to this bean in its XML file as a Componentb-datasource name. And in the main program MyApp XML configuration file, you want to refer to this bean by the name of Myapp-datasource. Finally, the container loads three XML files to generate the final applicationcontext, in which case it can be implemented by adding the following alias elements to the MyApp XML file:
<alias name= "Componenta-datasource" alias= "Componentb-datasource"/>
<alias name= "Componenta-datasource" alias= "Myapp-datasource"/>
In this way, each component and the main program can refer to the same data source by a unique name without interfering with each other.
Parsing of spring configuration file for spring profile