Spring Note 9-Spring's three important configurations (alias, bean, import)

A collection of all my spring notes
Spring5 introductory knowledge integration (continuous update)

At present, bean is used the most, and import will be used a lot in future teamwork.
Let’s talk about their respective usages one by one.

1. The alias keyword

First of all, alias is a tag in Spring's xml file. It represents an alias. For
example, you are called YSJ, and others always call you Caiboy. Even if Caiboy is your alias, for
example, if you have a bean whose id is called user, you can Use this tag to give this id an alias myUser, both of which are the same bean-id

Two ways to add alias

  • Attached directly to
    Insert picture description here
    this bean through the name tag , user is an alias with id myUser

  • Increase the
    use of aliases through the alias tag : <alias name="bean id" alias = "the alias you want to take" />
    Insert picture description here
    These two methods are equivalent, depending on personal usage, but name is more advanced than alias , it can take multiple aliases for an id at the same time
    Insert picture description here

2. Bean keyword

In fact, it is still used in many places in the front of the note, and there are some simple summaries in the front.

The configuration
id of the bean: the unique identifier of the bean, which is equivalent to the variable name we have learned
class: the type of bean object
name: an alias for this bean, and more advanced than alias, you can take multiple aliases (separated by commas) , Semicolon separation, space separation, etc. are all ok)

Insert picture description here
It is the soul of the SpringIOC container, hhh I understand this way

3. Import keyword

I don’t use this keyword very much at present (single-person development has always been). For
example, I have a one.xml configuration.
Insert picture description here
Through import, refer to one.xml in beans.xml, and just use the classpath.
Insert picture description here

Guess you like

Origin blog.csdn.net/YSJ367635984/article/details/113393174