Interface Injector


public interface Injector
Pluggable strategy for instantiating objects, optionally performing dependency injection as part of creation.

Camel uses the injector whenever it needs to create an instance of a user-supplied type (beans, processors, type converters, and so on) so that the surrounding runtime controls instantiation. The default implementation uses straightforward reflection, while runtimes such as Spring or Quarkus provide implementations that resolve and inject dependencies through their own container. The newInstance(Class) overloads support creation via a public no-arg constructor, a static factory method, a factory class, and with or without bean post processing applied by CamelBeanPostProcessor. supportsAutoWiring() reports whether the injector can autowire constructor dependencies.

See Bean Integration in the Camel user manual.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    newInstance(Class<T> type)
    Instantiates a new instance of the given type; possibly injecting values into the object in the process (bean post processing)
    <T> T
    newInstance(Class<T> type, boolean postProcessBean)
    Instantiates a new instance of the given type; possibly injecting values into the object in the process (bean post processing if enabled)
    <T> T
    newInstance(Class<T> type, Class<?> factoryClass, String factoryMethod)
    Instantiates a new instance of the given type by using the factory class (this will not perform bean post processing)
    <T> T
    newInstance(Class<T> type, String factoryMethod)
    Instantiates a new instance of the given type by using the factory method (this will not perform bean post processing)
    boolean
    Whether the injector supports creating new instances using auto-wiring.
  • Method Details

    • newInstance

      <T> T newInstance(Class<T> type)
      Instantiates a new instance of the given type; possibly injecting values into the object in the process (bean post processing)
      Parameters:
      type - the type of object to create
      Returns:
      a newly created instance
    • newInstance

      <T> T newInstance(Class<T> type, String factoryMethod)
      Instantiates a new instance of the given type by using the factory method (this will not perform bean post processing)
      Parameters:
      type - the type of object to create
      factoryMethod - to create the new instance via factory method which must be public static and return the type
      Returns:
      a newly created instance
    • newInstance

      <T> T newInstance(Class<T> type, Class<?> factoryClass, String factoryMethod)
      Instantiates a new instance of the given type by using the factory class (this will not perform bean post processing)
      Parameters:
      type - the type of object to create
      factoryClass - to create the new instance via factory class
      factoryMethod - to create the new instance via factory method which must be public static and return the type
      Returns:
      a newly created instance
    • newInstance

      <T> T newInstance(Class<T> type, boolean postProcessBean)
      Instantiates a new instance of the given type; possibly injecting values into the object in the process (bean post processing if enabled)
      Parameters:
      type - the type of object to create
      postProcessBean - whether to post process the bean
      Returns:
      a newly created instance
    • supportsAutoWiring

      boolean supportsAutoWiring()
      Whether the injector supports creating new instances using auto-wiring. If this is possible then bean instances is attempt first to be created this way and if not, then the bean can only be created if there is a public no-arg constructor.