|
对于最新稳定版本,请使用 Spring Integration 7.0.0! |
命名空间支持
你可以用直接映射到企业集成术语和概念的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">
(我们特别强调了春季整合特有的线条。)
你可以在“xmlns:”之后选择任何名字。
我们使用智力(积分的缩写)为了更清楚,但你可能更喜欢另一个缩写。
另一方面,如果你使用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 集成元素无需前缀。
另一方面,如果你在同一配置文件中定义通用的 Spring Bean,bean 元素需要前缀(<豆子:豆子....../>).
由于通常基于责任层或架构层对配置文件进行模块化是个好主意,你可能会觉得在集成型配置文件中使用后一种方法更合适,因为这些文件中很少需要通用豆子。
在本文档中,我们假设集成命名空间是主命名空间。
Spring Integration 提供了许多其他命名空间。
事实上,每个支持命名空间的适配器类型(如 JMS、文件等)都会在一个独立的模式中定义其元素。
为了使用这些元素,可以添加必要的命名空间,并使用XMLSNS元素及相应的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和模式位置的命名一致性。