This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • Tutorial on using Camel in a Web Application

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

Tutorial on using Camel in a Web Application

Camel has been designed to work great with the Spring framework; so if you are already a Spring user you can think of Camel as just a framework for adding to your Spring XML files.

So you can follow the usual Spring approach to working with web applications; namely to add the standard Spring hook to load a /WEB-INF/applicationContext.xml file. In that file you can include your usual Camel XML configuration.

Step1: Edit your web.xml

To enable spring add a context loader listener to your /WEB-INF/web.xml file

Code Block
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns=""



This will cause Spring to boot up and look for the /WEB-INF/applicationContext.xml file.

Step 2: Create a /WEB-INF/applicationContext.xml file

Now you just need to create your Spring XML file and add your camel routes or configuration.

For example

Code Block
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

  <camelContext xmlns="">
      <from uri="seda:foo"/>
      <to uri="mock:results"/>


Then boot up your web application and you're good to go!

Hints and Tips

If you use Maven to build your application your directory tree will look like this...

Code Block

You should update your Maven pom.xml to enable WAR packaging/naming like this...

Code Block
	<finalName>[desired WAR file name]</finalName>

To enable more rapid development we highly recommend the jetty:run maven plugin.

Please refer to the help for more information on using jetty:run - but briefly if you add the following to your pom.xml

Code Block

Then you can run your web application as follows

Code Block
mvn jetty:run

Then Jetty will also monitor your target/classes directory and your src/main/webapp directory so that if you modify your spring XML, your web.xml or your java code the web application will be restarted, re-creating your Camel routes.

If your unit tests take a while to run, you could miss them out when running your web application via

Code Block
mvn -Dtest=false jetty:run