Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: polished with how to add the Camel XML schema location

...

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.

  • Adding Camel schema
  • Configure Routes in two ways:
    • Using Java Code
    • Using Spring

...

    • XML

Adding Camel Schema

You need to add Camel to the schemaLocation declaration

Code Block

http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd

So the XML file looks like this:

Code Block
xml
xml

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
          http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">

Using camel: namespace

Or you can refer to camel XSD in the XML declaration:

Code Block

xmlns:camel="http://activemq.apache.org/camel/schema/spring"

... so the declaration is:

Wiki Markup
{snippet:id=xsdlocation|lang=xml|url=activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/camelContextFactoryBean.xml}

... and then use the camel: namespace prefix, and you can omit the inline namespace declaration:

Wiki Markup
{snippet:id=example5|lang=xml|url=activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/camelContextFactoryBean.xml}

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.

Wiki Markup
{snippet:id=exampleexample1|lang=xml|url=activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/camelContextFactoryBean.xml}

...

Wiki Markup
{snippet:id=example|lang=xml|url=activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/routingUsingCamelContextFactory.xml}

Or you can refer to camel XSD in the XML declaration:

Wiki Markup
{snippet:id=example5|lang=xml|url=activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/camelContextFactoryBean.xml}

... and then use the camel: namespace prefix, and you can omit the inline namespace declaration:

Wiki Markup
{snippet:id=example6|lang=xml|url=activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/camelContextFactoryBean.xml}

Configuring Components and Endpoints

...