Bean Injection

We support the injection of various resources using @EndpointInject or @BeanInject. This can be used to inject

Using @BeanInject

You can inject beans (obtained from the Registry) into your beans such as RouteBuilder classes.

For example to inject a bean named foo, you can enlist the bean in the Registry such as in a Spring XML file:

<bean id="foo" class="com.foo.MyFooBean"/>

And then in a Java RouteBuilder class, you can inject the bean using @BeanInject as shown below:

public class MyRouteBuilder extends RouteBuilder {

   @BeanInject("foo")
   MyFooBean foo;

   public void configure() throws Exception {
     ..
   }
}

If you omit the name, then Camel does a lookup by type, and injects the bean if there is exactly only one bean of that type enlisted in the Registry.

   @BeanInject
   MyFooBean foo;

Bean Injection with Quarkus or CDI

When using Camel with CDI, Spring Boot, or Quarkus, then the @Inject, or @Named annotations can be used to inject Camel resources as well.

Bean Injection with Spring Boot

Camel has first class support for Spring Boot, and you can use the Spring annotations such as @Autowired to also inject Camel resources.