面试-Spring-IoC&AOP理论 IoC容器原理

IoC

IoC - Inversion of Control

官方文档 IoC is also known as dependency injection(DI). It is a process whereby objects define their dependencies (that is, the other object they work with) only through constructor arguments, arguments to a factory method, or properties that are set on a object instance after it is constructored or returned from a factory method. This process is fundamentally the inverse (hance the name, Inversion of Control) of the bean itself controlling the instantiation or location of its dependencies by using direct constructions of classes or a mechanism such as the Service Locator pattern.
维基百科 控制反转(IoC)是一种面向对象编程中的一种设计原则,可以降低计算机代码之间的耦合度。其中,最常见的方式是依赖注入(DI, dependency Injection),还有一种方式叫做依赖查找(Dependency Lookup)。通过控制反转,对象在被创建的时候,由一个调控系统内所有对象的外界实体,将其所依赖的对象的引用传递(注入)给它。

AOP

Spring 2.x Aspect-Oriented Programming (AOP) complements Object-Oriented Programming (OOP) by providing another way of thinking about program structure. The key unit of modularity in OOP is the class, whereas in AOP the unit of modularity is the aspect. Aspects enable the modularization of concerns such as transaction management that cut across multiple types and objects.

IoC容器核心原理

    读取Bean配置信息,生成bean配置注册表,配置信息包括XML配置文件,@Configuration注解的配置类,@Autowired自动注入等 根据bean配置注册表实例化bean 建立好bean实例之间的依赖关系,并且把bean实例存放IOC容器的Bean缓存池中 应用程序使用bean实例
经验分享 程序员 微信小程序 职场和发展