1. Injection mode
In SpringBoot, you can inject properties, constructors, and corresponding setter methods.
@Component public class User{// @Autowired private ICorp corp; private IDept dept; // constructor injects @Autowired User(IDEPT dept){this.dept = dept; } // Autowired public void IRED (IXx xx){}}
As you can see from the above code, there are three ways to inject, each of which can be done by using a specific annotation such as @Autowired
2. Inject annotations
Common injection annotations in Spring include: @Autowired, @Qulified, and @Resource.
- @Autowired looks up beans of the corresponding type by the type of the property; if it looks for more than one, it looks up the variable name of the property as the name of the bean
- @Qulified is often used in conjunction with @Autowired, which can be used to specify a name if there are more than one bean of the type
- @resouce (name=”xx”) looks for the name value of the bean specified by the name, and if it looks for more than one, it will be excluded by the type of the attribute