Interface CamelBeanPostProcessor


public interface CamelBeanPostProcessor
Processes beans as they are created or registered, applying Camel's annotation-based dependency injection.

For every bean it inspects, the post processor wires up the Camel injection annotations such as EndpointInject, Produce, Consume, BeanInject, and PropertyInject, and binds BindToRegistry beans into the Registry. Processing runs in two phases, postProcessBeforeInitialization(Object, String) and postProcessAfterInitialization(Object, String), mirroring the well-known Spring BeanPostProcessor lifecycle so a bean can be enriched both before and after its own init callbacks. Runtimes that already perform their own injection (Spring, Quarkus, CDI) supply their own implementations, while the default runtime uses reflection. Custom injection for 3rd-party annotations can be plugged in via CamelBeanPostProcessorInjector, and CamelDependencyInjectionAnnotationFactory controls how BindToRegistry beans are bound. Bean post processing can be disabled via setEnabled(boolean) for runtimes that do not use these Camel features.

See Bean Injection in the Camel user manual.

Since:
3.0
See Also:
  • Method Details

    • postProcessBeforeInitialization

      default @Nullable Object postProcessBeforeInitialization(Object bean, @Nullable String beanName) throws Exception
      Apply this post processor to the given new bean instance before any bean initialization callbacks (like afterPropertiesSet or a custom init-method). The bean will already be populated with property values. The returned bean instance may be a wrapper around the original.
      Parameters:
      bean - the new bean instance
      beanName - the name of the bean
      Returns:
      the bean instance to use, either the original or a wrapped one; if null, no subsequent BeanPostProcessors will be invoked
      Throws:
      Exception - is thrown if error post processing bean
    • postProcessAfterInitialization

      default @Nullable Object postProcessAfterInitialization(Object bean, @Nullable String beanName) throws Exception
      Apply this post processor to the given new bean instance after any bean initialization callbacks (like afterPropertiesSet or a custom init-method). The bean will already be populated with property values. The returned bean instance may be a wrapper around the original.
      Parameters:
      bean - the new bean instance
      beanName - the name of the bean
      Returns:
      the bean instance to use, either the original or a wrapped one; if null, no subsequent BeanPostProcessors will be invoked
      Throws:
      Exception - is thrown if error post processing bean
    • setEnabled

      default void setEnabled(boolean enabled)
      Can be used to turn off bean post processing. Be careful to turn this off, as this means that beans that use Camel annotations such as EndpointInject, ProducerTemplate, Produce, Consume etc will not be injected and in use. Turning this off should only be done if you are sure you do not use any of these Camel features.
    • isEnabled

      default boolean isEnabled()
      Whether bean post processing is enabled.
    • setUnbindEnabled

      default void setUnbindEnabled(boolean unbindEnabled)
      Sets whether to unbind any existing beans before binding a bean to the registry.
      See Also:
    • isUnbindEnabled

      default boolean isUnbindEnabled()
      Can be used to unbind any existing beans before binding a bean to the registry. Be careful to enable this, as this will unbind all beans with the given id. This is used in special use-cases such as reloading of Camel routes which triggered updating beans that have their implementation re-compiled and re-loaded.
    • addCamelBeanPostProjectInjector

      default void addCamelBeanPostProjectInjector(CamelBeanPostProcessorInjector injector)
      Adds a custom bean post injector
      Parameters:
      injector - the custom injector
    • setLazyBeanStrategy

      void setLazyBeanStrategy(Predicate<BindToRegistry> strategy)
      Custom strategy for handling BindToRegistry beans and whether they are lazy or not.
    • getLazyBeanStrategy

      Predicate<BindToRegistry> getLazyBeanStrategy()
      Custom strategy for handling BindToRegistry beans and whether they are lazy or not.