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

命名空间

路由器 schema>_<- the definition XML DSL-abrtbelongs 到以下 XML 模式命名空间:

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

指定 schema 位置

路由器模式的位置通常指定为 http://camel.apache.org/schema/spring/camel-spring.xsd,它引用 Apache Web 站点上 schema 的最新版本。例如,Apache Camel Spring 文件的 root Bean 元素通常配置为 例 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>

运行时模式位置

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

使用 XML 编辑器

通常,建议您使用全功能 XML 编辑器编辑 Spring 文件。借助 XML 编辑器的自动完成功能,编写符合路由器架构的 XML 更轻松,如果 XML 不正确,编辑器也会立即提醒您。

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

<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