I am trying to learn Spring and understand how it works. I have followed some tutorials in setting up Spring and Camel, and have had it working using default setups.
I am now attempting to convert as much as possible of my configuration XML-files to Java-classes. So far I have been successful in creating the camel-routes in a Java-class (extending SpringRouteBuilder and implementing configure() ), and all the beans from my spring-configuration file (Bean->Function with @Bean). The only part I am missing is the camelContext definition (?) that starts my camel routes (I think...):
<camel:camelContext id="camel5">
<camel:package>net.krg.kneip.routing</camel:package>
</camel:camelContext>
What would the equivalent non-XML of this be?
Not sure if it will help, but here is my AppConfig class so far: http://pastebin.com/vsRAbpK1
Thanks!
SOLUTION:
@Bean
public CamelContext camel() throws Exception{
CamelContext camelContext = new DefaultCamelContext();
camelContext.addRoutes(new net.krg.kneip.routing.Routes());
camelContext.start();
return camelContext;
}
Spring Boot component provides auto-configuration for Apache Camel. Our opinionated auto-configuration of the Camel context auto-detects Camel routes available in the Spring context and registers the key Camel utilities (like producer template, consumer template and the type converter) as beans.
The CamelContext is the runtime system, which holds everything together as depicted in the figure below. The CamelContext provides access to many useful services, the most notable being components, type converters, a registry, endpoints, routes, data formats, and languages. Contains the components used.
Camel auto configuration collects all the RouteBuilder instances from the Spring context and automatically injects them into the CamelContext . It simplifies the process of creating new Camel route with the Spring Boot starter. You can create the routes by adding the @Component annotated class to your classpath.
The autoStartup option on the <camelContext> is only used once, so you can manually start Camel later by invoking its start method in Java as shown below. For example when using Spring, you can get hold of the CamelContext via the Spring ApplicationContext : ApplicationContext ac = ... CamelContext camel = ac.
CamelContext context = new DefaultCamelContext();
I think this is what you're looking for.
Read more here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With