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
Configuration parameter index matching injection
Injection type matching configuration parameters
① Set injection method
Get, Set method:
Xml file configuration:
JUnit test class:
JUnit test results:
Reproduced in: https: //www.cnblogs.com/H_Razor/archive/2011/05/04/Vazor_Lou.html