4.5. 使用上下文扫描
您可以允许 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 样式包含和排除,如软件包扫描部分所述。