Spring Series on --Spring IOC dependency injection

  Typical enterprise application is not a single bean components. There is no doubt that even the simplest systems require multiple objects together to present to the user a whole application. Spring processing and a range of configuration dependencies, you will be presented below.

  Dependency injection is Spring part of the core technology, dependency injection ( the DI ) is the basic principle behind the dependencies between objects will be achieved by the following ways: Parameter constructors, the factory method, constructor, or by the individual or object factory method to create the set properties. So the work is to create a container of bean inject those dependencies when. With respect to the handling of dependencies to Bean 's own process, this injection method advantage, which reflects the low coupling design mode, but without losing the function, which is the inversion of control ( Inversion of Control ) IOC origin of the word.

  ① constructor injection:

    Construction methods and parameters

    2011050420540823.png 

    Configuration parameter index matching injection

    2011050420552688.png  

    Injection type matching configuration parameters

    2011050420562890.png

  ① Set injection method

      Get, Set method:

      2011050420573272.png

       Xml file configuration:

        2011050420582243.png

  JUnit test class:

    2011050420592898.png

  JUnit test results:

    2011050421000466.png

Reproduced in: https: //www.cnblogs.com/H_Razor/archive/2011/05/04/Vazor_Lou.html

Guess you like

Origin blog.csdn.net/weixin_33894992/article/details/93313391