春天如何加载多个骆驼上下文

时间:2020-06-19 13:09:05

标签: spring apache-camel

我想在Spring Java应用程序中上传多个骆驼上下文文件(camel-context.xml; camel-context2.xml)。我正在尝试以下方式上传文件。但是只加载单个文件。

@SpringBootApplication
@ImportResource({"classpath:camel*.xml"})

在下面的控制台快照中,蓝色标记为成功响应,红色标记为错误。

enter image description here

Note : I have tried this approach as well . Didnt workout.
@ImportResource("camel-context.xml", "camel-context2.xml")

1 个答案:

答案 0 :(得分:1)

https://camel.apache.org/manual/latest/camel-3-migration-guide.html#_multiple_camelcontexts_per_application_not_supported

已删除了对多个CamelContext的支持,每个部署仅支持1个CamelContext。无论如何,不​​建议使用后者,也不是100%实施(例如,在camel-cdi中)。对于Camel 3,建议仅支持每个部署1个CamelContext。

但是您仍然可以按照以下方式来分离路由配置,因为这仍然是一个骆驼环境。 https://camel.apache.org/manual/latest/faq/how-do-i-import-routes-from-other-xml-files.html

文件1:

<beans ....">

    <routeContext id="myCoolRoutes" xmlns="http://camel.apache.org/schema/spring">

        <route id="cool">
            <from uri="direct:start"/>
            <to uri="mock:result"/>
        </route>
        <route id="bar">
            <from uri="direct:bar"/>
            <to uri="mock:bar"/>
        </route>
    </routeContext>
</beans>

文件2 :(文件1已导入)

<beans ..>
    
    <import resource="myCoolRoutes.xml"/>

    <camelContext xmlns="http://camel.apache.org/schema/spring">

        <routeContextRef ref="myCoolRoutes"/>

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

</beans>