Namespace Support
您可以使用直接映射到企业集成术语和概念的 XML 元素配置 Spring Integration 组件。在许多情况下,元素名称与 Enterprise Integration Patterns书中的名称匹配。
You can configure Spring Integration components with XML elements that map directly to the terminology and concepts of enterprise integration. In many cases, the element names match those of the Enterprise Integration Patterns book.
要在您的 Spring 配置文件中启用 Spring Integration 的核心命名空间支持,请在您的顶级“bean”元素中添加以下命名空间引用和架构映射:
To enable Spring Integration’s core namespace support within your Spring configuration files, add the following namespace reference and schema mapping in your top-level 'beans' element:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration" xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd">
(我们强调了特定于 Spring Integration 的行。)
(We have emphasized the lines that are particular to Spring Integration.)
您可以在“xmlns:”后面选择任何名称。我们使用 int
(Integration 的缩写)以清楚起见,但您可能更喜欢其他缩写。另一方面,如果您使用 XML 编辑器或 IDE 支持,则自动完成的可用性可能会让您确信保留较长的名称以清楚起见。或者,您可以创建以 Spring Integration 架构为主要命名空间的配置文件,如下例所示:
You can choose any name after "xmlns:".
We use int
(short for Integration) for clarity, but you might prefer another abbreviation.
On the other hand, if you use an XML editor or IDE support, the availability of auto-completion may convince you to keep the longer name for clarity.
Alternatively, you can create configuration files that use the Spring Integration schema as the primary namespace, as the following example shows:
<beans:beans xmlns="http://www.springframework.org/schema/integration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd">
(我们强调了特定于 Spring Integration 的行。)
(We have emphasized the lines that are particular to Spring Integration.)
使用此备选方案时,Spring Integration 元素不需要前缀。另一方面,如果您在同一配置文件中定义通用 Spring bean,则 bean 元素需要一个前缀(<beans:bean …/>
)。由于通常最好对配置文件本身进行模块化(基于职责或架构层),因此您可能会发现适合在以集成为主的配置文件中使用后一种方法,因为这些文件很少需要通用 bean。出于本文档的目的,我们假设集成命名空间是主要的。
When using this alternative, no prefix is necessary for the Spring Integration elements.
On the other hand, if you define a generic Spring bean within the same configuration file, the bean element requires a prefix (<beans:bean …/>
).
Since it is generally a good idea to modularize the configuration files themselves (based on responsibility or architectural layer), you may find it appropriate to use the latter approach in the integration-focused configuration files, since generic beans are seldom necessary within those files.
For the purposes of this documentation, we assume the integration namespace is the primary.
Spring Integration 提供了许多其他命名空间。事实上,为命名空间支持提供每种适配器类型(JMS、文件等)在单独模式内定义其元素。要使用这些元素,请添加包含 xmlns
条目和相应 schemaLocation
映射的必要命名空间。例如,以下根元素显示了这些命名空间声明中的几个:
Spring Integration provides many other namespaces.
In fact, each adapter type (JMS, file, and so on) that provides namespace support defines its elements within a separate schema.
In order to use these elements, add the necessary namespaces with an xmlns
entry and the corresponding schemaLocation
mapping.
For example, the following root element shows several of these namespace declarations:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-file="http://www.springframework.org/schema/integration/file"
xmlns:int-jms="http://www.springframework.org/schema/integration/jms"
xmlns:int-mail="http://www.springframework.org/schema/integration/mail"
xmlns:int-ws="http://www.springframework.org/schema/integration/ws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
https://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/file
https://www.springframework.org/schema/integration/file/spring-integration-file.xsd
http://www.springframework.org/schema/integration/jms
https://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd
http://www.springframework.org/schema/integration/mail
https://www.springframework.org/schema/integration/mail/spring-integration-mail.xsd
http://www.springframework.org/schema/integration/ws
https://www.springframework.org/schema/integration/ws/spring-integration-ws.xsd">
...
</beans>
本参考手册在其相应章节中提供了各种元素的具体示例。在这里,主要事项是要识别每个命名空间 URI 和模式位置的命名一致性。
This reference manual provides specific examples of the various elements in their corresponding chapters. Here, the main thing to recognize is the consistency of the naming for each namespace URI and schema location.