Spring 5.0.8.RELEASE文档 Core1-1.1 介绍Spring IoC和Beans

版权声明:mj1001001 https://blog.csdn.net/qq_42786889/article/details/81529698

Core
IoC container, Events, Resources, i18n, Validation, Data Binding, Type Conversion, SpEL, AOP

核心部分:包括IOC容器、事件、资源获取、i18n国际化、校验、数据绑定、类型转换、Spring表达式、AOP。(其中校验、数据绑定、类型转换、资源获取在项目中属于搭建配置约定好的,可能直接用的比较少,一般无形中用得比较多,因为ssm已经配置好了)

This part of the reference documentation covers all of those technologies that are absolutely integral to the Spring Framework.

Foremost amongst these is the Spring Framework’s Inversion of Control (IoC) container. A thorough treatment of the Spring Framework’s IoC container is closely followed by comprehensive coverage of Spring’s Aspect-Oriented Programming (AOP) technologies. The Spring Framework has its own AOP framework, which is conceptually easy to understand, and which successfully addresses the 80% sweet spot of AOP requirements in Java enterprise programming.

Coverage of Spring’s integration with AspectJ (currently the richest - in terms of features - and certainly most mature AOP implementation in the Java enterprise space) is also provided.

这核心技术这一部分的内容是Spring框架必不可少的技术组成(英文:这些技术绝对是构成Spring框架整体所需要的(也就是绝对使得Spring框架完整的)-,-)

其中最重要的就是IoC容器,经过彻底的优化后IoC几乎被全面覆盖上了Spring AOP技术。(AOP:面向切面编程,即统一代理)Spring框架拥有它自己的AOP框架,并且它的AOP是易懂易使用的,能满足Java使用AOP开发80%的爽处。

Spring框架同样提供了集成AspectJ作为替换其AOP的实现的能力(AspectJ是Java界口碑最好的AOP框架之一)


1.. The IoC container
1.1. Introduction to the Spring IoC container and beans
This chapter covers the Spring Framework implementation of the Inversion of Control (IoC) principle. IoC is also known as dependency injection (DI). It is a process whereby objects define their dependencies, that is, the other objects they work with, only through constructor arguments, arguments to a factory method, or properties that are set on the object instance after it is constructed or returned from a factory method. The container then injects those dependencies when it creates the bean. This process is fundamentally the inverse, hence the name Inversion of Control (IoC), of the bean itself controlling the instantiation or location of its dependencies by using direct construction of classes, or a mechanism such as the Service Locator pattern.

1.. IoC容器
1.1. 介绍IoC容器和beans
这个章节包括了Spring框架实现IoC(控制翻转)的理念。IoC也被称为依赖注入(DI)。它是一个对象声明它所需要的依赖的过程,设置依赖一般需要通过构造函数参数、工厂方法设置参数、实例化对象然后设置属性几种。而Spring容器可以自动注入依赖当容器在创建这些对象的时候。整个过程从根本上反转了,因此命名为控制反转,这些bean就可以自己来控制实例化和添加自己的依赖,或者利用服务定位模式的机制(类似find xml上定义的路径)

The org.springframework.beans and org.springframework.context packages are the basis for Spring Framework’s IoC container. The BeanFactory interface provides an advanced configuration mechanism capable of managing any type of object. ApplicationContext is a sub-interface of BeanFactory. It adds easier integration with Spring’s AOP features; message resource handling (for use in internationalization), event publication; and application-layer specific contexts such as the WebApplicationContext for use in web applications.

The org.springframework.beans 和 org.springframework.context这两个包是Spring IoC容器的基础。BeanFactory 工厂接口提供了完美(先进)的配置方式适用于管理任何类型的对象。ApplicationContext 是BeanFactory接口的子接口。它能很容易地添加集成Spring AOP细节、消息资源处理(国际化)、事件发布、特殊的应用层上下文(Context)如WebApplicationContext 这种—一般使用在web应用上的

In short, the BeanFactory provides the configuration framework and basic functionality, and the ApplicationContext adds more enterprise-specific functionality. The ApplicationContext is a complete superset of the BeanFactory, and is used exclusively in this chapter in descriptions of Spring’s IoC container. For more information on using the BeanFactory instead of the ApplicationContext, refer to The BeanFactory.

简单的说,BeanFactory 提供了配置框架和Spring的基本功能,而且ApplicationContext添加了更多企业级开发的基础能力。ApplicationContext是BeanFactory的超集,并且在此章节中仅用于描述Spring IoC容器。但如果想使用BeanFactory来代替ApplicationContext的话你可以参考BeanFactory页

In Spring, the objects that form the backbone of your application and that are managed by the Spring IoC container are called beans. A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container. Otherwise, a bean is simply one of many objects in your application. Beans, and the dependencies among them, are reflected in the configuration metadata used by a container.

在Spring,应用中骨干的对象且被Spring IoC容器所管理的,都可以称之为beans。一个bean是对象的实例,是已经装配好的(设置好依赖),并且由Spring IoC容器来管理。另外bean除了会被自动注入依赖之外还能反映出Spring容器对其进行的元数据的配置(如在xml配置实例化注入的参数)

猜你喜欢

转载自blog.csdn.net/qq_42786889/article/details/81529698
今日推荐