7.14. 在类路径中添加 XML 路由以进行自动配置

默认情况下,Camel Spring Boot 组件会自动探测,并包含 camel 目录中的 classpath 中的 Camel XML 路由。您可以使用配置选项配置目录名称或禁用此功能。

流程

  • 在类路径中配置 Camel Spring Boot XML 路由,如下所示:

    // turn off
    camel.springboot.xmlRoutes = false
    // scan in the com/foo/routes classpath
    camel.springboot.xmlRoutes = classpath:com/foo/routes/*.xml
    注意

    XML 文件应该定义 Camel XML 路由元素而不是 CamelContext 元素,例如:

       <routes xmlns="http://camel.apache.org/schema/spring">
            <route id="test">
                <from uri="timer://trigger"/>
                <transform>
                    <simple>ref:myBean</simple>
                </transform>
                <to uri="log:out"/>
            </route>
        </routes>

使用 Spring XML 文件

要将 Spring XML 文件与 <camelContext> 搭配使用,您可以在 Spring XML 文件或 application.properties 文件中配置 Camel 上下文。要设置 Camel 上下文的名称并打开流缓存,请在 application.properties 文件中添加以下内容:

camel.springboot.name = MyCamel
camel.springboot.stream-caching-enabled=true