Tool direction: three ways of injecting data in spring

1. Introduction

  1. Constructor
  2. set method
  3. annotation

2. Constructor injection

2.1 Customized classes

Insert image description here

2.2 Writing xml files

Insert image description here

3. set method injection

3.1 Customized classes

Insert image description here

3.2 Writing xml files

Insert image description here

4. Annotation injection

4.1 @AutoWired

The IOC container only needs one bean object of this type to use automatic injection.
Insert image description here

4.2 @AutoWired + @Qualifier (bean objects of the same type exist)

The IOC container has more than one bean object of the same type (with different names).
Which bean object is the name of @Qualifier?

Insert image description here

4.3 @Resource (find it directly by name)

Insert image description here

Guess you like

Origin blog.csdn.net/qq_44716086/article/details/105922095