Spring SupportApache Camel is designed to work nicely with the Spring Framework
Using Spring to configure the CamelContextYou can configure a CamelContext inside any spring.xml using the CamelContextFactoryBean Using Spring you can configure Routes in two ways Using Java CodeYou 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 <bean id="camel" class="org.apache.camel.spring.CamelContextFactoryBean"> <property name="packages" value="org.apache.camel.spring.example"/> </bean> Or if you prefer you can use the Spring 2.0 XML Namespaces approach <camelContext id="camel3" xmlns="http://activemq.apache.org/camel/schema/spring"> <package>org.apache.camel.spring.example</package> </camelContext> Using Spring XMLYou can use Spring 2.0 XML configuration to specify your Xml Configuration for Routes such as in the following example <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring"> <route> <from uri="seda:start"/> <to uri="mock:result"/> </route> </camelContext> Configuring Components and EndpointsYou can configure your Component or Endpoint instances in your Spring XML as follows in this example <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring"> </camelContext> <bean id="activemq" class="org.apache.camel.component.jms.JmsComponent"> <property name="connectionFactory"> <bean class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerURL" value="vm://localhost?broker.persistent=false"/> </bean> </property> </bean> 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. |