1.3. Spring XML 文件中的路由器架构

命名空间

路由器 schema iwl-busybox,它定义了 XML DSL iwl-wagonbelongs 到以下 XML 模式命名空间:

http://camel.apache.org/schema/spring

指定模式位置

路由器模式的位置通常指定为 http://camel.apache.org/schema/spring/camel-spring.xsd,它引用 Apache 网站上模式的最新版本。例如,Apache Camel Spring 文件的 root beans 元素通常会配置,如 例 1.2 “指定路由器架构位置” 所示。

例 1.2. 指定路由器架构位置

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

  <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
    <!-- Define your routing rules here -->
  </camelContext>
</beans>

Runtime 模式位置

在运行时,Apache Camel 不会从 Spring 文件中指定的模式位置下载路由器模式。相反,Apache Camel 会自动从 camel-spring JAR 文件的根目录中获取模式的副本。这样可确保用于解析 Spring 文件的 schema 版本始终与当前的运行时版本匹配。这很重要,因为在 Apache 网站上发布的最新版本的模式可能与您当前使用的运行时版本不匹配。

使用 XML 编辑器

通常,建议您使用功能齐全的 XML 编辑器编辑 Spring 文件。XML 编辑器的自动完成功能使编写 XML 更容易编写,该模式符合路由器模式,编辑器会立即警告,如果 XML 不正确。

XML 编辑器 通常 依赖于从您在 xsi:schemaLocation 属性中指定的位置下载模式。为了确保您使用正确的模式版本 whilst 编辑,通常最好选择 camel-spring.xsd 文件的特定版本。例如,要编辑 2.3 版本的 Apache Camel 的 Spring 文件,您可以修改 beans 元素,如下所示:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring-2.3.0.xsd">
...

编辑完成后,请改回到默认的 camel-spring.xsd。要查看哪些架构版本当前可用于下载,请进入网页 http://camel.apache.org/schema/spring