image.png

    Field injection is not recommended less… (Ctrl+F1)
    Inspection info: Spring Team recommends: “Always use constructor based dependency injection in your beans. Always use assertions for mandatory dependencies”.

    参考文章:https://cloud.tencent.com/developer/article/1126880

    使用构造器注入的好处:

    1. 保证依赖不可变(final关键字)
    2. 保证依赖不为空(省去了我们对其检查)
    3. 保证返回客户端(调用)的代码的时候是完全初始化的状态
    4. 避免了循环依赖
    5. 提升了代码的可复用性