从 Spring 注释配置初始化骆驼 [英] Initializing camel from Spring annotation config

查看:33
本文介绍了从 Spring 注释配置初始化骆驼的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习 Spring 并了解它的工作原理.我遵循了一些设置 Spring 和 Camel 的教程,并使用默认设置使其工作.

我现在正在尝试将尽可能多的配置 XML 文件转换为 Java 类.到目前为止,我已经成功地在 Java 类中创建了骆驼路由(扩展 SpringRouteBuilder 并实现了 configure() ),以及我的弹簧配置文件(Bean->Function with @Bean)中的所有 bean.我唯一缺少的部分是开始我的骆驼路线的骆驼上下文定义(?)(我认为......):

<camel:package>net.krg.kneip.routing</camel:package></camel:camelContext>

与此等效的非 XML 是什么?

不确定它是否会有所帮助,但到目前为止,这是我的 AppConfig 类:http://pastebin.com/vsRAbpK1

谢谢!

解决方案:

@Beanpublic CamelContext camel() 抛出异常{CamelContext camelContext = new DefaultCamelContext();camelContext.addRoutes(new net.krg.kneip.routing.Routes());camelContext.start();返回骆驼上下文;}

解决方案

CamelContext context = new DefaultCamelContext();

我认为这就是您要找的.

在这里阅读更多

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

解决方案

CamelContext context = new DefaultCamelContext();

I think this is what you're looking for.

Read more here

这篇关于从 Spring 注释配置初始化骆驼的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆