spring_dependency injection

DI Dependency Injection, Dependency Injection

	is a : is one, inherited.
	has a: there is one, member variable, dependent.
		class B {
           private A a; //Class B depends on Class A
        }
	Dependency: An object needs to use another object
	Injection: Another object instance setting via a setter method.
E.g:
	class BookServiceImpl{
        //Previous development: interface = implementation class (coupling of service and dao)
		//private BookDao bookDao = new BookDaoImpl();
 		//After spring (decoupling: the service implementation class uses the dao interface, I don't know the specific implementation class)
		private BookDao bookDao;
		setter method
   }
	Simulate the spring execution process
	Create a service instance: BookService bookService = new BookServiceImpl() -->IoC <bean>
	Create a dao instance: BookDao bookDao = new BookDaoImple() -->IoC
	Set dao to service: bookService.setBookDao(bookDao); -->DI <property>



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325816768&siteId=291194637