搜索

4.5. 使用上下文扫描

download PDF

您可以允许 Camel 扫描容器上下文,例如,用于路由构建器实例的 Spring ApplicationContext。这可让您使用 Spring < component-scan& gt; 功能,并在扫描过程中选择由 Spring 创建的任何 RouteBuilder 实例。

<!-- enable Spring @Component scan -->
<context:component-scan base-package="org.apache.camel.spring.issues.contextscan"/>

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <!-- and then let Camel use those @Component scanned route builders -->
    <contextScan/>
</camelContext>

这可让您使用 Spring @Component 注解路由,并包含这些路由:

@Component
public class MyRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        from("direct:start")
            .to("mock:result");
    }
}

您还可以使用 ANT 样式包含和排除,如软件包扫描部分所述。

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

© 2024 Red Hat, Inc.