如需使用最新稳定版本,请使用 Spring Integration 7.0.4spring-doc.cadn.net.cn

命名空间支持

您可以使用与企业集成术语和概念直接映射的 XML 元素来配置 Spring Integration 组件。 在许多情况下,元素名称与《Enterprise Integration Patterns》一书中的名称相匹配。spring-doc.cadn.net.cn

要在您的 Spring 配置文件中启用 Spring Integration 的核心命名空间支持,请在顶层 'beans' 元素中添加以下命名空间引用和模式映射:spring-doc.cadn.net.cn

<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特有的行。)spring-doc.cadn.net.cn

您可以在"xmlns:"后选择任意名称。 为了清晰起见,我们使用int(Integration 的缩写),但您可能更喜欢其他缩写。 另一方面,如果您使用支持自动补全的 XML 编辑器或 IDE,其可用性可能会说服您保留较长的名称以增强清晰度。 或者,您可以创建将 Spring Integration 模式作为主要命名空间的配置文件,如下例所示:spring-doc.cadn.net.cn

<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特有的行。)spring-doc.cadn.net.cn

使用此替代方案时,Spring Integration 元素不需要前缀。 另一方面,如果在同一配置文件中定义通用的 Spring bean,则 bean 元素需要前缀(<beans:bean …​/>)。 由于通常将配置文件本身模块化(基于职责或架构层)是一个好主意,因此您可能会发现在以集成为重点的配置文件中采用后一种方法是合适的,因为这些文件中很少需要通用 bean。 出于本文档的目的,我们假设集成命名空间是主要的。spring-doc.cadn.net.cn

Spring Integration 提供了许多其他命名空间。 事实上,每个提供命名空间支持的适配器类型(如 JMS、文件等)都在单独的架构中定义其元素。 为了使用这些元素,请添加必要的命名空间,并在 xmlns 条目中添加相应的 schemaLocation 映射。 例如,以下根元素展示了其中几个命名空间声明:spring-doc.cadn.net.cn

<?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 和架构位置命名的一致性。spring-doc.cadn.net.cn