2015-02-10 87 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添加到路由。