300.9.5.3. 使用 XML 文件


您还可以使用 XML DSL 定义 Camel 路由,尽管我们不使用 Spring 或 Blueprint,而 XML 文件只能包含 Camel 路由。

在 web.xml 中,您可以引用来自 "classpath"、"file" 或 "http" url 的 XML 文件,如下所示:

  <context-param>
    <param-name>routeBuilder-MyRoute</param-name>
    <param-value>classpath:routes/myRoutes.xml</param-value>
  </context-param>
Copy to Clipboard

XML 文件是:

routes/myRoutes.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- the xmlns="http://camel.apache.org/schema/spring" is needed -->
<routes xmlns="http://camel.apache.org/schema/spring">

  <route id="foo">
    <from uri="direct:foo"/>
    <to uri="mock:foo"/>
  </route>

  <route id="bar">
    <from uri="direct:bar"/>
    <to uri="mock:bar"/>
  </route>

</routes>
Copy to Clipboard

请注意,在 XML 文件中,root 标签为 <routes>,必须使用命名空间 "http://camel.apache.org/schema/spring"。此命名空间在名称中包含 spring,但由于历史原因,因为 Spring 是首次存在,因此此时只有 XML DSL。在运行时不需要 Spring JAR。或许在 Camel 3.0 中,命名空间可以重命名为通用名称。

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat