Search Tutorials


Spring Boot Tutorial - Integrate Spring Boot + Apache Camel | JavaInUse

Spring Boot Tutorial- Integrate Spring Boot+ Apache Camel

In this example we see how to use Apache Camel with a Spring Boot Application.
Apache Camel is a rule-based routing and mediation engine that provides a Java object-based implementation of the Enterprise Integration Patterns using an API (or declarative Java Domain Specific Language) to configure routing and mediation rules. More tutorials for Apache Camel can be found in Apache Camel Section

Video

This tutorial is explained in the below Youtube Video.

Lets Begin-

Maven Project will be as follows-

Spring Boot Apache Camel Example

In the Maven we need the camel dependency.Maven will be as follows-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.javainuse</groupId>
  <artifactId>springboot-camel</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
 <dependencies>

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-spring-boot-starter</artifactId>
    <version>2.17.0</version>
</dependency>

</dependencies>
</project>
Create the SpringBootHelloWorldApplication.java as below-
package com.javainuse;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringBootHelloWorldApplication {

	public static void main(String[] args) {
		SpringApplication.run(SpringBootHelloWorldApplication.class, args);
	}
}
Next we add class with the Camel routes.This routes will be started automatically.
package com.javainuse;

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

@Component
public class MyRoute extends RouteBuilder {

	@Override
	public void configure() throws Exception {
		from("file:C://inputFolder?noop=true").to("file:C://outputFolder");
	}
}





To keep the main thread blocked so that Camel stays up,add camel.springboot.main-run-controller=true to the application.properties.
camel.springboot.main-run-controller=true

This is the only code needed to get started.
Compile and the run the SpringBootHelloWorldApplication.java as a Java application.

Spring Boot Apache Camel Tutorial
As can be seen above one route has been started. It copies files from inputFolder to the outputFolder.

Download Source Code

Download it -
Spring Boot + Apache Camel

See Also

Spring Boot Hello World Application- Create simple controller and jsp view using Maven Spring Boot Tutorial-Spring Data JPA Spring Boot + Simple Security Configuration Pagination using Spring Boot Simple Example Spring Boot + ActiveMQ Hello world Example Spring Boot + Swagger Example Hello World Example Spring Boot + Swagger- Understanding the various Swagger Annotations Spring Boot Main Menu Spring Boot Interview Questions