我剛開始在我的一個項目中使用Camel。我試圖用Spring配置Camel,但遇到問題。
我不想使用xml配置,而是使用基於Spring的Annotations來配置路由和處理器。CamelContext沒有采用Spring註釋的路線
我的應用程序是一個獨立的Spring應用程序,它將作爲Jar運行。 爲了保持應用程序的運行,我有一個空的預定方法,每運行x分鐘。
下面是我build.gralde
// Spring //
compile('org.springframework:spring-core:5.0.0.RC2')
compile('org.springframework:spring-context:5.0.0.RC2')
compile('org.springframework:spring-beans:5.0.0.RC2')
compile('org.springframework:spring-context-support:5.0.0.RC2')
// Apache //
// Camel //
compile('org.apache.camel:camel-core:2.19.1')
compile('org.apache.camel:camel-spring:2.19.1')
快照beans.xml
<context:annotation-config/>
<tx:annotation-driven/>
<context:component-scan base-package="my.package" />
<camelContext id="aggregatorCamelContext" autoStartup="true" xmlns="http://camel.apache.org/schema/spring">
<package>
my.package.camel
</package>
</camelContext>
樣品的依賴RouteBuilder
@Component
public class SampleRoute extends RouteBuilder {
@Autowired
MyClass myObject;
@Override
public void configure() throws Exception {
from("file:filelist")
.process(myObject)
.to("file:processedList");
}
}
爲了保持應用程序活着(我知道有點哈克,但就足夠了現在)
@Component
@EnableScheduling
public class KeepitAlive {
@Scheduled(fixedRate = 1000l)
public void run(){
System.out.println("KeepitAlive.run "+ Thread.currentThread().getName());
}
}
Main Class。我曾嘗試這兩種方法,初始化Spring上下文以及駱駝爲主,但沒有運氣
public class MyApplication {
public static void main(String[] args) throws Exception {
/*AbstractXmlApplicationContext context =
new ClassPathXmlApplicationContext("path/to/beans.xml");*/
Main main = new Main();
main.setApplicationContextUri("path/to/beans.xml");
main.start();
}
}
如果我把我的路線camelContext聲明本身,它的作品精美絕倫,
<route>
<from uri="file:filelist"/>
<to uri="file:processedlist"/>
</route>
我我們也研究過駱駝春季整合documentation,但它也包含基於xml的配置。
任何人都可以請指導我正確的方向。
使用'run'方法在'Main'類如果從Apache的駱駝。看到這個FAQ:http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html –