Camel CLI - Java Beans
When running Camel integrations with the CLI, the runtime is camel-main based — there is no Spring Boot or Quarkus container. However, annotation-based dependency injection is supported across all three styles: Camel-native, Spring Boot, and Quarkus annotations.
| There is basic support for including regular Java source files together with Camel routes. The CLI compiles them at runtime, so you can include utility classes, POJOs, processors, and other classes your application needs. |
Using Camel dependency injection
Camel-native annotations for standalone use:
-
@BindToRegistryon a class — creates an instance and registers it in the Registry -
@Configurationon a class — runs during Camel startup for custom setup code -
@BeanInjecton a field — injects a bean from the Registry -
@PropertyInjecton a field — injects a property placeholder value -
@BindToRegistryon a method — creates a bean by invoking the method -
@Converteron a class — auto-registers type converters
@BeanInject can reference beans annotated with @BindToRegistry, but the dependency must be registered before the dependent bean. |
Using Spring Boot dependency injection
These Spring annotations work in Camel standalone (no Spring container required):
-
@Componentor@Serviceon a class — registers an instance in the Registry -
@Autowiredon a field — injects a bean (@Qualifierspecifies the bean id) -
@Valueon a field — injects a property placeholder -
@Beanon a method — creates a bean by invoking the method
Using Quarkus dependency injection
These Jakarta/MicroProfile annotations work in Camel standalone (no Quarkus container required):
-
@ApplicationScopedor@Singletonon a class — registers an instance (@Namedspecifies the bean id) -
@Injecton a field — injects a bean (@Namedspecifies the bean id) -
@ConfigPropertyon a field — injects a property placeholder -
@Produceson a method — creates a bean (@Namedspecifies the bean id)
Defining beans in XML DSL
<camel>
<bean name="beanFromMap" type="com.acme.MyBean">
<properties>
<property key="foo" value="bar" />
</properties>
</bean>
</camel> Properties can use nested <property> elements or dotted notation:
<camel>
<!-- nested properties style -->
<bean name="beanFromMap" type="com.acme.MyBean">
<properties>
<property key="field1" value="f1_p" />
<property key="nested">
<properties>
<property key="field1" value="nf1_p" />
</properties>
</property>
</properties>
</bean>
<!-- dotted properties style -->
<bean name="beanFromProps" type="com.acme.MyBean">
<properties>
<property key="field1" value="f1_p" />
<property key="nested.field1" value="nf1_p" />
</properties>
</bean>
</camel> Using Spring Beans XML in Camel XML DSL
You can use Spring Beans XML namespace inside Camel XML DSL. The beans are added to the Registry — this does not require Spring Framework at runtime.
Supported features:
-
Dependency injection
-
Constructor injection
-
Dependency cycles
-
Wiring existing Camel objects (like
CamelContext)
<camel>
<beans xmlns="http://www.springframework.org/schema/beans">
<bean id="messageString" class="java.lang.String">
<constructor-arg index="0" value="Hello"/>
</bean>
<bean id="greeter" class="org.apache.camel.main.app.Greeter">
<property name="message">
<bean class="org.apache.camel.main.app.GreeterMessage">
<property name="msg" ref="messageString"/>
</bean>
</property>
</bean>
</beans>
<route id="my-route">
<from uri="direct:start"/>
<bean ref="greeter"/>
<to uri="mock:finish"/>
</route>
</camel> Predefined Camel beans
These beans can be referenced without declaring them:
-
CamelContext— the currentorg.apache.camel.CamelContext -
MainConfiguration— theorg.apache.camel.main.MainConfigurationPropertiesinstance
For example:
<beans xmlns="http://www.springframework.org/schema/beans">
<bean id="greeter" class="org.apache.camel.main.app.Greeter">
<property name="camelContext" ref="CamelContext"/>
</bean>
</beans> Customizing Camel internals
You can register beans that affect CamelContext configuration. For example, to replace the default UUID generator:
<camel>
<beans xmlns="http://www.springframework.org/schema/beans">
<bean id="customUUIDGenerator" class="org.apache.camel.support.ShortUuidGenerator" />
</beans>
</camel> Camel looks up known SPI types (like UuidGenerator) in the Registry and uses them automatically.