• Spring Dependency Injection (DI)

  • 发表时间:2019-03-05 02:07 | 优美女人网(ym27.com) | 点击数:
  •   In Spring frameowork, Dependency Injection (DI) design pattern is used to define the object dependencies between each other. It exits in two major types :

      - Setter Injection

      - Constructor Injection

      This is the most popular and simple DI method, it will injects the dependency via a setter method.

      A helper class with a setter method.

      A bean configuration file to declare the beans and set the dependency via setter injection ( tag).

      You just injects a ‘’ bean into ‘’ object via a setter method ().

      This DI method will injects the dependency via a constructor.

      Example

      A helper class with a constructor.

      A bean configuration file to declare the beans and set the dependency via constructor injection ( tag).

      You just injects a ‘’ bean into ‘’ object via a constructor.

      There are no hard rule set by Spring framework, just use whatever type of DI that suit your project needs. However, due to the simplicity of the setter injection, it’s always selected for most of the scenarios.

分享到:
  • 上一篇:MSL-Radiology 下一篇:没有了
  • 相关 竞技 资讯
    精彩图库
    • 网游
    • 竞技
    • 娱乐
    • 通知
    文章页 右侧底部 300x250 广告
    Copyright @ 2011-2017