面试-Spring-IoC&AOP理论 IoC容器原理「建议收藏」

面试-Spring-IoC&AOP理论 IoC容器原理「建议收藏」IoCIoC-InversionofControl官方文档IoCisalsoknownasdependencyinjection(DI).Itisaprocesswherebyobjectsdefinetheirdependencies(thatis,theotherobjecttheyworkwith)onlythroughconstructorarguments,argumentstoafactorymethod,or

大家好,欢迎来到IT知识分享网。

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.

维基百科
面向切面的程序设计(Aspect-oriented programming,AOP)是计算机科学中的一种程序设计思想,旨在将横切关注点与业务主体进行进一步分离,以提高程序代码的模块化程度。通过在现有代码基础上增加额外的通知(Advice)机制,能够对被声明为“切点(Pointcut)”的代码块进行统一管理与装饰。该思想使得开发人员能够将与代码核心业务逻辑关系不那么密切的功能(如日志功能)添加至程序中,同时又不降低业务代码的可读性。面向切面的程序设计思想也是面向切面软件开发的基础。

IoC容器核心原理

在这里插入图片描述

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

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/24912.html

(0)
上一篇 2023-08-08 09:00
下一篇 2023-08-09 20:00

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

关注微信