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

Compare with Current View Page History

« Previous Version 13 Next »

Spring Support

Apache Camel is designed to work nicely with the Spring Framework in a number of ways.

  • Camel uses Spring Transactions as the default transaction handling in components like JMS and JPA
  • Camel works with Spring 2 XML processing with the Xml Configuration
  • Camel integrates with various Spring helper classes; such as providing Type Converter support for Spring Resources etc
  • Allows Spring to dependency inject Component instances or the CamelContext instance itself and auto-expose Spring beans as components and endpoints.

Using Spring to configure the CamelContext

You can configure a CamelContext inside any spring.xml using the CamelContextFactoryBean. This will automatically start the CamelContext along with any referenced Routes along any referenced Component and Endpoint instances.

Using Spring you can configure Routes in two ways

Using Java Code

You can use Java Code to define your RouteBuilder implementations, then in your spring.xml you can specify the Java package names to search for (recursively) to find your routes such as in the following example.

Error formatting macro: snippet: java.lang.NullPointerException

Or if you prefer you can use the Spring 2.0 XML Namespaces approach

Error formatting macro: snippet: java.lang.NullPointerException

Using Spring XML

You can use Spring 2.0 XML configuration to specify your Xml Configuration for Routes such as in the following example.

Error formatting macro: snippet: java.lang.NullPointerException

Configuring Components and Endpoints

You can configure your Component or Endpoint instances in your Spring XML as follows in this example.

Error formatting macro: snippet: java.lang.NullPointerException

Which allows you to configure a component using some name (activemq in the above example), then you can refer to the component using activemq:[queue:|topic:]destinationName. This works by the SpringCamelContext lazily fetching components from the spring context for the scheme name you use for Endpoint URIs.

For more detail see Configuring Endpoints and Components.

  • No labels