1.2.2.1 Composing XML-based Configuration Metadata组合基于XML的配置元数据

 Spring Framework Documentation (5.3.10)

Core

IoC Container, Events, Resources, i18n, Validation, Data Binding, Type Conversion, SpEL, AOP.

 Core Technologies

1. The IoC Container

1.1. Introduction to the Spring IoC Container and Beans(Spring IoC容器和bean简介)

1.2. Container Overview (容器概览)

1.2.1. Configuration Metadata (配置元数据)

1.2.2. Instantiating a Container(实例化一个容器)

1.2.2.1 Composing XML-based Configuration Metadata(组合基于XML的配置元数据)

1.2.2.2 The Groovy Bean Definition DSL (Groovy Bean定义DSL)

1.2.3. Using the Container (使用容器)

1.3. Bean Overview (Bean概览)


下载此文档精编完整版

 No. 内容 下载地址 文档内容目录
1 中英双语精编版 第一部分 PDF下载 内容目录
2 中英双语精编版 第二部分 PDF下载 内容目录
3 中文精编版 第一部分 PDF下载 内容目录
4 中文精编版 第二部分 PDF下载 内容目录

更多章节内容,请点击查看:  Core Technologies


1.2.2.1 Composing XML-based Configuration Metadata组合基于XML的配置元数据

It can be useful to have bean definitions span multiple XML files. Often, each individual XML configuration file represents a logical layer or module in your architecture.

bean定义跨越多个XML文件可能很有用。通常,每个单独的XML配置文件都表示你的体系结构中的一个逻辑层或模块。

You can use the application context constructor to load bean definitions from all these XML fragments. This constructor takes multiple Resource locations, as was shown in the previous section. Alternatively, use one or more occurrences of the  element to load bean definitions from another file or files. The following example shows how to do so:

您可以使用应用程序上下文(application context)构造函数通过这些XML片段来加载bean定义。此构造函数获取多个Resource 位置,如前一节所示。或者,使用一个或多个< import />元素从另一个(或多个)文件加载bean定义。以下示例展示了如何执行此操作:


    
    
    

    
    

In the preceding example, external bean definitions are loaded from three files: services.xmlmessageSource.xml, and themeSource.xml. All location paths are relative to the definition file doing the importing, so services.xml must be in the same directory or classpath location as the file doing the importing, while messageSource.xml and themeSource.xml must be in a resources location below the location of the importing file. As you can see, a leading slash is ignored. However, given that these paths are relative, it is better form not to use the slash at all. The contents of the files being imported, including the top level  element, must be valid XML bean definitions, according to the Spring Schema.

在前述示例中,从三个文件加载外部bean定义:services.xmlmessageSource.xmlthemeSource.xml。所有位置路径都与执行导入的定义文件相关,因此services.xml必须与执行导入的文件位于同一目录或类路径(classpath)位置,而messageSource.xmlthemeSource.xml必须位于导入文件位置下的resources 位置。如您所见,前导斜杠被忽略。然而,考虑到这些路径是相对的,最好不要使用斜杠。根据Spring Schema,要导入的文件的内容,包括顶级元素,必须是有效的XML bean定义。

It is possible, but not recommended, to reference files in parent directories using a relative "../" path. Doing so creates a dependency on a file that is outside the current application. In particular, this reference is not recommended for classpath: URLs (for example, classpath:../services.xml), where the runtime resolution process chooses the “nearest” classpath root and then looks into its parent directory. Classpath configuration changes may lead to the choice of a different, incorrect directory.

You can always use fully qualified resource locations instead of relative paths: for example, file:C:/config/services.xml or classpath:/config/services.xml. However, be aware that you are coupling your application’s configuration to specific absolute locations. It is generally preferable to keep an indirection for such absolute locations — for example, through "${…​}" placeholders that are resolved against JVM system properties at runtime.

可以(但不建议)使用 ./ 相对路径引用父目录中的文件。这样做会创建对当前应用程序之外的文件的依赖关系。特别是,不建议对classpath:url(例如,classpath:../services.xml)使用此引用,其中运行时解析过程选择“最近的”classpath根,然后查看其父目录。Classpath配置更改可能会导致选择不同的、不正确的目录。

您始终可以使用完全限定的资源位置(fully qualified resource location)而不是相对路径:例如,file:C:/config/services.xmlclasspath:/config/services.xml。但是,请注意,您正在将应用程序的配置耦合到特定的绝对位置。通常,最好为此类绝对位置保留一个间接层。例如,通过在运行时根据JVM系统属性解析的“${…}”占位符。

The namespace itself provides the import directive feature. Further configuration features beyond plain bean definitions are available in a selection of XML namespaces provided by Spring — for example, the context and util namespaces.

命名空间本身提供导入指令功能(import directive feature)。更多配置特性(不同于普通bean定义)包含在Spring提供的一系列XML命名空间中。例如,context util命名空间。

你可能感兴趣的:(#,Core,Technologies,#,BPMN用户指南(1)入门,XML-based,Configuration,Metadata)