You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Spring Example

The spring example is a simple refactor of the first example to show how to use the Spring approach to working with Camel. In this example we just write RouteBuilder implementations, then we write a Spring ApplicationContext XML file to configure Camel.

To run the example we use the Camel Maven Plugin. For example from the source or binary distribution the following should work

cd camel-example-spring
mvn camel:run

What this does is boot up the Spring ApplicationContext defined in the file META-INF/spring/camel-context on the classpath. This is a regular Spring XML document which uses the Camel Xml Configuration to configure a CamelContext. Notice how the <camelContext> element is configured

  <camelContext packages="org.apache.camel.example.spring">
     ...

The packages attribute defines the comma separated list of Java package names which are recursively searched for Java classes on the classpath which implement the RouteBuilder interface. This allows us to write the Camel routes using the Java DSL and just wire together in XML what we really need to.

Also note in this XML file we explicitly configure the ActiveMQ component with details of how to connect to the broker.

  • No labels