跳到主要内容
版本:7.0.2

命名空间支持

DeepSeek V3 中英对照 Namespace Support

你可以使用直接映射到企业集成术语和概念的 XML 元素来配置 Spring Integration 组件。在许多情况下,元素名称与《企业集成模式》一书中的名称一致。

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

<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 特有的代码行。)

你可以在 xmlns: 后选择任意名称。为了清晰起见,我们使用 int(Integration 的缩写),但你也可以选择其他缩写。另一方面,如果你使用 XML 编辑器或 IDE 支持,自动补全功能的可用性可能会让你倾向于保留更长的名称以保持清晰。或者,你也可以创建使用 Spring Integration 模式作为主命名空间的配置文件,如下例所示:

<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 Integration 元素无需前缀。另一方面,如果在同一配置文件中定义通用 Spring bean,则 bean 元素需要前缀 (<beans:bean …​/>)。由于通常建议根据职责或架构层对配置文件本身进行模块化,您可能会发现在以集成功能为主的配置文件中采用后一种方法是合适的,因为这类文件中很少需要通用 bean。在本文档中,我们假定集成命名空间是主要命名空间。

Spring Integration 提供了许多其他命名空间。实际上,每种提供命名空间支持的适配器类型(JMS、文件等)都在单独的 schema 中定义其元素。要使用这些元素,请通过 xmlns 条目添加必要的命名空间以及相应的 schemaLocation 映射。例如,以下根元素展示了其中几个命名空间声明:

<?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和模式位置命名的一致性。