camel file copy example using spring

File copy example in camel using spring with simple steps.

In this example we will learn how can we copy file from one location to other location using camel through spring.

  • In eclipse go to MyFirstCamelProject that we created in earlier page and right click on src/main/java to create package.New -> package

  • Give any name for example com.preparationforinterview.spring.filetransfer and click on Finish

  • Right click on package and create a java class for example FileTransferinSpring.

  • Right click on src/main/resources and and create one .xml file for example MySpring.xml.

  • Create two folder one with name input and other as output.At the end we will get following structure

  • Create any file in input folder.I created text file with name Hello.

  • Add following dependency in pom.xml can use any latest version.

    <project xmlns="" xmlns:xsi=""
  • Run mvn:install from command prompt or if you are using Eclipse right click on pom.xml and run mvn install.It will download camel jars

  • Copy below code in FileTransferinSpring.

    package com.preparationforinterview.spring.filetransfer;
    public class FileTransferinSpring {
    	public static void main(String args[]) throws InterruptedException {
    		AbstractApplicationContext ctx = new ClassPathXmlApplicationContext(
    		Thread.sleep(5 * 60 * 1000);


    In this example we are loading spring file and starting CamelContext.When we start CamelContext ,it will start to read message from input and will send it to destination.

  • Write lines in MySpring.xml.

    	<beans xmlns=""
    	xmlns:xsi="" xmlns:camel=""
    	xsi:schemaLocation="       ">
    	<camelContext xmlns="">
    			<from uri="file:input?noop=true" />
    			<to uri="file:output" />


    Last entry in xml file <camelContext xmlns=""/> creates SpringCamelContext which provides CamelContext.In CamelContext we have add route so when we start spring application that routes also start

    To check the output right click on and run it. It will copy file in output folder from input folder
    To run the program from command prompt,open command prompt and go to project location and run below command.
    mvn compile exec:java -Dexec.mainClass=com.preparationforinterview.spring.filetransfer.FileTransferinSpring

Download source code

Camel File Copy Example Using Spring

Visit Others Links

Camel Introduction
Camel Setup
File Copy Example Using Camel
File Copy Example In Camel Using Spring
JMS Message Transfer Example Using Camel
JMS Message Transfer Example In Camel Using Spring
Processor In Camel
Object to JSON Transfer Example Using Spring In Camel
Camel With Bean Injection Example Using Spring DSL
Camel With Bean Injection Registry Example Using Java DSL
Camel Bean Parameter Binding Example Using Java DSL
Camel Error Handling With Redelivery Example Using Java DSL
Camel Exception Handling With Example Using Java DSL
Camel JUnit Test With Example Using Java DSL
Camel JUnit Test With Example Using Spring DSL
Camel Unit Test With Mock Component Example
Camel With Stream Component Example
Camel In-Memory Messaging Example Using Direct
Camel With Timer And Quartz Example
Camel Aggregator EIP Example
Camel Splitter EIP Example
Camel Routing Slip EIP Example
Camel Dynamic Router EIP Example
Camel Load Balancer EIP Example
Top Camel Interview Question
© 2019