2015-02-10 90 views
-1

一点背景:无法添加骆驼路线

我使用Spring和骆驼与Java 8

public static void main(String[] args) throws Exception { 

    AbstractApplicationContext _context = new ClassPathXmlApplicationContext(
      "application-context.xml"); 
    _context.registerShutdownHook(); 

    MessageRoute _messageRoute = (MessageRoute) _context.getBean("messageRoute"); 
    SpringCamelContext _camelContext = _context.getBean(SpringCamelContext.class); 
    _messageRoute.setContext(_camelContext); 
    _camelContext.addRoutes(_messageRoute); 

    Object lock = new Object(); 
    synchronized (lock) { 
     lock.wait(); 
    } 

    ((ClassPathXmlApplicationContext) _context).close(); 

} 

[主] DEBUG oscePropertySourcesPropertyResolver在一起 - 搜索键“spring.liveBeansView。 mbeanDomain'[systemProperties] [main] DEBUG oscePropertySourcesPropertyResolver - 在[systemEnvironment]中搜索键'spring.liveBeansView.mbeanDomain' [main] DEBUG oscePropertySourcesPropertyResolver - 无法在任何属性中找到键'spring.liveBeansView.mbeanDomain'资源。返回[空] [主] DEBUG osbfsDefaultListableBeanFactory - 返回单豆 'messageRoute' [主] DEBUG osbfsDefaultListableBeanFactory的缓存实例 - 返回缓存的单bean实例, 'org.apache.camel.spring.SpringCamelContext#0' [主] DEBUG oacamel.spring.SpringCamelContext - 从建设者添加路线:路线:[] [主] DEBUG oacamel.spring.SpringCamelContext - 从建设者添加路线:路线:[]

我已经尝试使用DefaultCamelContext,但问题是它只是不添加路由类。 MessageRoute类是一个扩展RouteBuilder的简单类。我的观察告诉我包含以下内容的行:_context.getBean(“messageRoute”)可能有问题,因为它没有将任何路由传递给RouteBuilder参考。

debugger view

回答

0

中加入Java航线XML,只需使用<routeBuilder ref="myBeanName"/><camelContext>

见骆驼文档:http://camel.apache.org/spring.html在部分使用Java代码

+0

我知道我可以试试XML的方式,但我这是怎么用骆驼2.10添加路由,他们会很好地工作。我可以继续以XML方式进行操作,但为什么Camel不遵守Spring的ApplicationContext中创建的bean。我需要一个很好的推理。可能是我做了一些我看不到的错误,或者可能是它的一个真正的春天+骆驼问题。 – Bytekoder 2015-02-10 15:07:02

+0

相同的代码适用于骆驼2.10和春天3.x!此外,不知道我的问题是如此错误,以至于它被低估了。 – Bytekoder 2015-02-10 15:13:20

0

别介意我固定它! Camel并没有在Spring容器中添加一个Route类的实例,因为在configure方法中,需要一个从()。()到()的实际路径。

非常有趣,虽然它并没有抛出任何错误,甚至拒绝了ApplicationContext的bean添加到路由。