您的位置:首页 > 编程语言 > Java开发

Spring Framework Reference Documentation(1)

2016-03-18 19:10 441 查看

翻译:Spring Framework Reference Documentation

翻译章节:

The Ioc container

Resources

Validation,Data Binding,and Type Conversion

Spring Expression Language(SpEL)

Aspect Oriented Programming with Spring

Spring AOP APIs

Testing

第五章:IoC容器

容器概念

The interface org.springframework.context.ApplicationContext represents the Spring IoC container and is responsible for instantiating, configuring, and assembling the aforementioned beans. The container gets its instructions on what objects to instantiate, configure, and assemble by reading configuration metadata. The configuration metadata is represented in XML, Java annotations, or Java code. It allows you to express the objects that compose your application and the rich interdependencies between such objects.

org.springframework.context.ApplicationContext 接口代表Spring IoC容器,并且负责对前面提到的bean的实例化,配置和装配。容器通过阅读配置元数据,得到哪些对象需要被实例化,配置

和组合的指示。这些配置元数据通常实在通过在XML,java注解或者时Java代码来表示。容器允许你表达组成你应用程序的这些对象,和在这些对象中的丰富的依赖关系。

Several implementations of the ApplicationContext interface are supplied out-of-the-box with Spring. In standalone applications it is common to create an instance of ClassPathXmlApplicationContext or FileSystemXmlApplicationContext. While XML has been the traditional format for defining configuration metadata you can instruct the container to use Java annotations or code as the metadata format by providing a small amount of XML configuration to declaratively enable support for these additional metadata formats.

ApplicationContext 接口多次实现了由Spring提供的对外封装。在独立的应用程序中,建立一个ClassPathXmlApplicaitonContext 或者一个 FileSystemXmlApplicationContext 的实例是再寻常不过的。虽然,XML已由传统的格式用来定义配置元数据,可以指示容器通过提供少量的XML配置,以声明使这些这些附加的元数据格式的支持使用JAVA注解或代码作为元数据格式的容器。

In most application scenarios, explicit user code is not required to instantiate one or more instances of a Spring IoC container. For example, in a web application scenario, a simple eight (or so) lines of boilerplate web descriptor XML in the web.xml file of the application will typically suffice (see the section called “Convenient ApplicationContext instantiation for web applications”). If you are using the Spring Tool Suite Eclipse-powered development environment this boilerplate configuration can be easily created with few mouse clicks or keystrokes.

在绝大多数应用场景下,不需要明确的用户代码来实例化一个或者多个Spring的Ioc容器中的实例。例如,在web应用程序场景中,在应用程序的web.xml文件中,通常8行左右的模板web的描述性xml就够了(参见”Convenient ApplicationContext instantiation for web applications”一节)。如果你是正在基于Eclipse开发环境使用Spring工具套件,这个模板配置可以简单得通过点击几下鼠标或者键盘便能创建了。

The following diagram is a high-level view of how Spring works. Your application classes are combined with configuration metadata so that after the ApplicationContext is created and initialized, you have a fully configured and executable system or application.

下面是Spring工作原理的一个高级别图。你的应用程序类文件和配置元数据相结合,以便在 ApplicationContext 创建和实例化后,你可以拥有一个完全配置好的可执行的系统或应用。



图5.1 Spring IoC容器

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: