Apache Camel Spring Boot starters
Camel support for Spring Boot provides auto-configuration of the Camel and starters for many Camel components. Our opinionated auto-configuration of the Camel context auto-detects Camel routes available in the Spring context and registers the key Camel utilities (like producer template, consumer template and the type converter) as beans.
Get started by adding the Camel Spring Boot BOM to your Maven pom.xml
file.
<dependencyManagement>
<dependencies>
<!-- Camel BOM -->
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-dependencies</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- ... other BOMs or dependencies ... -->
</dependencies>
</dependencyManagement>
Next, add the Camel Spring Boot starter to startup the Camel Context.
<dependencies>
<!-- Camel Starter -->
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
</dependency>
<!-- ... other dependencies ... -->
</dependencies>
And any component starters your Spring Boot application requires. For example this adds the starter for the ActiveMQ component.
<dependencies>
<!-- ... other dependencies ... -->
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-activemq-starter</artifactId>
</dependency>
</dependencies>
Making sure Camel context is running in standalone Spring Boot
To ensure the Spring Boot application keeps running until being stopped or the JVM terminated, typically only need when running Spring Boot standalone, i.e. not with spring-boot-starter-web
when the web container keeps the JVM running, set the camel.springboot.main-run-controller=true
property in your configuration. For example in application.properties
.
# to keep the JVM running
camel.springboot.main-run-controller = true
Spring Boot configuration support
Each component starter lists configuration parameters you can configure in the standard application.properties
or application.yml
files. These parameters have the form of camel.component.[component-name].[parameter]
. For example to configure the URL of the ActiveMQ broker you can set:
camel.component.activemq.broker-u-r-l=tcp://localhost:61616
Adding Camel routes
Camel routes are detected in the Spring application context, for example a route annotated with org.springframework.stereotype.Component
will be loaded, added to the Camel context and run.
import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;
@Component
public class MyRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
from("...")
.to("...");
}
}