Loading routes from XML filesAvailable as of Camel 2.6 This cookbook shows how to load and add routes from XML files into an existing CamelContext. You can define Camel routes in XML files using the <routes> tag with the namespace "http://camel.apache.org/schema/spring". barRoute.xml <routes xmlns="http://camel.apache.org/schema/spring"> <!-- here we define the bar route --> <route id="bar"> <from uri="direct:bar"/> <to uri="mock:bar"/> </route> <!-- we could add more routes if we like, but in this example we stick to one route only --> </routes> We can then load this route and add to the existing CamelContext using the following lines of code: Java code // load route from XML and add them to the existing camel context InputStream is = getClass().getResourceAsStream("barRoute.xml"); RoutesDefinition routes = context.loadRoutesDefinition(is); context.addRouteDefinitions(routes.getRoutes()); If you are using older versions of Camel, you can do this as well but it requires a bit more work. See this commit log. |