Solvemon
Solvemon

Reputation: 1461

Initializing camel from Spring annotation config

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;      
}

Upvotes: 7

Views: 7263

Answers (1)

U2one
U2one

Reputation: 381

CamelContext context = new DefaultCamelContext();

I think this is what you're looking for.

Read more here

Upvotes: 7

Related Questions