6.8. 配置自定义 Camel 上下文

要对 Camel Spring Boot 自动配置创建的 CamelContext bean 执行操作,请在 Spring 上下文中注册 CamelContextConfiguration 实例。

流程

  • 在 Spring 上下文中注册 CamelContextConfiguration 实例,如下所示。

    @Configuration
    public class MyAppConfig {
    
      ...
    
      @Bean
      CamelContextConfiguration contextConfiguration() {
        return new CamelContextConfiguration() {
          @Override
          void beforeApplicationStart(CamelContext context) {
            // your custom configuration goes here
          }
        };
      }
    
    }

在 Spring 上下文启动前,CamelContext ConfigurationbeforeApplicationStart ( CamelContext ) 方法被调用,因此传递给此回调的 CamelContext 实例会被完全自动配置。您可以将许多 CamelContextConfiguration 实例添加到 Spring 上下文中,并且所有实例都将被执行。