我刚开始在我的一个项目中使用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 –