Parsing of spring configuration file for spring profile

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.