In Apache Camel on Spring Boot, @Component is Spring's stereotype annotation, and its job is to turn a RouteBuilder subclass into a Spring bean. The Camel Spring Boot starter collects every RoutesBuilder bean from the application context and adds its routes to the CamelContext at startup, so annotating the class is what makes the route run.
Camel itself does not define @Component. The word also names something else in Camel, a connector such as timer: or file:, so the two meanings are easy to confuse. This article covers the Spring annotation.
The same word appears in two places, and they are unrelated:
| Term | What it is | Example |
|---|---|---|
Spring @Component | Stereotype annotation that registers a class as a Spring bean | @Component public class OrderRoutes extends RouteBuilder |
| Camel component | A connector that creates endpoints for a URI scheme | timer, file, kafka, http |
When someone asks about the role of @Component in Camel, they mean the first row: how your own classes get picked up by the Spring container so Camel can use them.
Add the Camel Spring Boot starter and write a route class. Using Maven:
Then declare the route:
With @Component, Spring component scanning (enabled by @SpringBootApplication) creates the bean. The Camel starter then discovers it because it implements RoutesBuilder, and it calls configure() while starting the context. Remove @Component and the class is never instantiated, so the route silently does not exist. That is the most common reason a new route does not start.
Running the application prints a line like this every five seconds:
Because the route is a normal Spring bean, you can inject other beans. Prefer constructor injection over field @Autowired: the dependency is explicit, final, and easy to mock in tests.
The bean(orderService, "validate") step calls the method with the message body as its argument and replaces the body with the return value. You can also reference a bean by name in the Simple language or with .to("bean:orderService?method=validate"); Camel looks it up in the Spring registry.
Routes are not the only candidates. Anything Camel needs to find by type or by name can be a bean:
org.apache.camel.Processor, referenced with .process(myProcessor).choice() blocks.ThreadPoolProfile objects defined in @Configuration classes with @Bean.Use @Configuration with @Bean instead when you need to construct a bean with specific arguments, or when the class comes from a library you cannot annotate.
Camel Spring Boot supports several properties in application.properties that interact with component scanning:
The java-routes-* patterns filter which RouteBuilder beans are loaded, which is handy for turning routes off per environment without touching code. For conditional registration you can also combine @Component with Spring's @Profile or @ConditionalOnProperty.
In Spring Boot, yes, unless you register the builder another way, for example with an @Bean method. The starter only sees beans in the Spring context.
@Component registers the class itself through scanning. @Bean registers an instance created in a @Configuration method, which lets you pass constructor arguments or wrap a class you do not own.
Check that the class is in a package below your @SpringBootApplication class, that it has @Component, and that camel.springboot.java-routes-exclude-pattern does not match it.
Yes. They are specialisations of @Component and behave identically for scanning. Use the one that describes the role of the class.
@Component makes a Camel RouteBuilder a Spring bean, which is how the Camel Spring Boot starter finds and starts it. It also lets you use constructor injection to bring services into routes. Do not confuse it with Camel components such as timer or kafka, which are connectors, and use include and exclude patterns when you need to control which route classes load.