Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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.

...

You need to add Camel to the schemaLocation declaration

Code Block
http://activemqcamel.apache.org/camel/schema/spring http://activemqcamel.apache.org/camel/schema/spring/camel-spring.xsd

...

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://activemqcamel.apache.org/camel/schema/spring http://activemqcamel.apache.org/camel/schema/spring/camel-spring.xsd">

...

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

...

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

...

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=example1|lang=xml|url=activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/camelContextFactoryBean.xml}

...

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

...

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

...

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

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

...

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

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

...

If you want to be injected with the CamelContext in your POJO just implement the CamelContextAware interface; then when Spring creates your POJO the CamelContext will be injected into your POJO. Also see the Bean Integration for further injections.

...