In this tutorial you will learn how to bootstrap Camel in a Spring Boot Application in a matter of minutes!

First of all, let's create our project from a basic Web template:

spring init -dweb spring-camel

Ok, we have included the web starter as part of our kit, we will now add Apache Camel dependencies so that we can start firing routes. Include in your pom.xml camel dependencies as follows:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""
	<description>Demo project for Spring Boot</description>







In order to trigger the Camel wheel, we need to inject the CamelContext in our application. To make it really simple, we will inject it into the main class:

package com.example.springcamel;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.apache.camel.CamelContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.apache.camel.builder.RouteBuilder;

public class DemoApplication {

	CamelContext camelContext;

	public static void main(String[] args) {, args);

    public CommandLineRunner commandLineRunner(ApplicationContext ctx) {

       return args -> {

            camelContext.addRoutes(new RouteBuilder() {
             public void configure() {



As you can see, we have added a new Camel route using the fluent syntax of the RouteBuilder class. This simple Camel route will copy files from a source folder to a destination folder. Make sure you have the path of the file Component available on your machine.

Now run the application in any of the possible ways, such as:

java -jar target/spring-camel-0.0.1-SNAPSHOT.jar

You will see from the output that the Camel route has been bootstrapped and executed:

2018-12-11 10:44:31.248  INFO 12432 --- [       Thread-3] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2018-12-11 10:44:31.249  INFO 12432 --- [       Thread-3] o.a.camel.spring.SpringCamelContext      : Apache Camel 2.17.0 (CamelContext: camel-1) is shutting down
2018-12-11 10:44:31.250  INFO 12432 --- [       Thread-3] o.a.camel.impl.DefaultShutdownStrategy   : Starting to graceful shutdown 1 routes (timeout 300 seconds)
2018-12-11 10:44:31.254  INFO 12432 --- [ - ShutdownTask] o.a.camel.impl.DefaultShutdownStrategy   : Route: route1 shutdown complete, was consuming from: Endpoint[file:///home/frank/test/in?noop=true]
2018-12-11 10:44:31.254  INFO 12432 --- [       Thread-3] o.a.camel.impl.DefaultShutdownStrategy   : Graceful shutdown of 1 routes completed in 0 seconds

As a proof of concept, check the destination folder to see if files have been copied from the source.

Starting a Camel Route from a Spring REST Service

If you want to start a Camel Route upon a request, the simplest way is by means of a REST Service. Just plug one in:

package com.example.springcamel;

import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

public class CamelController {
	CamelContext camelContext;
	ProducerTemplate producerTemplate;

	@RequestMapping(value = "/camel")
	public void startCamel() {
                System.out.println("Received call!");  
		producerTemplate.sendBody("direct:demoRoute", "Calling via Spring Boot Rest Controller");

Now we need a consumer for that route, so just add one:

package com.example.springcamel;

import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;

public class CamelRoute extends RouteBuilder{

	public void configure() throws Exception {
			.log("Got message: ${body}");


Now reach the "/camel" endpoint from the browser or shell:

curl http://localhost:8080/camel

You will see that in your Spring Boot Console, the log message is printed:

Camel body: Calling via Spring Boot Rest Controller
FREE WildFly Application Server - JBoss - Quarkus - Drools Tutorials