Spring Java Config Example
Want to run your jar file and supply a list of packages / configuration classes and just see it run with Camel? Try Main
from org.apache.camel.spring
which even supports command-line flags.
The spring java config example is a simple refactor of the spring example since Camel 2.0 to show how to use the Spring JavaConfig approach to working with Camel. In this example we just write RouteBuilder implementations, then Camel will find it through your configuration.
NOTE From Camel 2.2.0, camel-example-spring-javaconfig can only work with Spring 3.x.
To run the example we use the Camel Maven Plugin. For example from the source or binary distribution the following should work
You need to add camel-spring-javaconfig dependency into pom.xml and also set the configure class or base package in the camel plugin configuration.
Here is the configuration for camel plugin.
What this does is boot up the Spring ApplicationContext defined in the file MyRouteConfig class on the classpath. This is a regular Java file which has the Spring JavaConfig annotation to configure a CamelContext.
In the method of setupCamelContext(CamelContext camelContext), we setup the JMS component's connection factory and register the component into the camelcontext. You can override this method if you want to setup the another connection factory or start up a JMS broker here.
You can write the route rule with Java DSL in the route() method.
This approach, of using Java code to write the routes in the DSL and Spring will help your configure the Camel context as the Spring Java Config Example shows.