我是使用 Camel Spring DSL 路由的新手。我的经验主要是使用 Java DSL。
我最近看了一个基于 Camel Spring DSL 的项目,发现整个 项目仅包含 XML 路由和一些用于特殊处理器的支持类。 我无处可以找到一个 Java 类来实际Start 路线运行。我期待着 找到一个以以下内容开头的课程:
@SpringBootApplication
public class LocalAppRunner {
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(LocalAppRunner.class);
springApplication.setBanner(new TraneBanner());
springApplication.setAdditionalProfiles("local");
springApplication.setBannerMode(Banner.Mode.LOG);
springApplication.run(args);
}
但显然不需要任何课程(作为项目的一部分公开编写) 启动路线。
我的猜测是路线开始于类似 mvn spring-boot:run
任何人都可以澄清我在这个假设中是否正确,即 Spring DSL 不需要公开的 Java(or Groovy)类来启动路由,但可以仅依赖 mvn 引用,如上所示。 (当然 POM 文件需要正确的条目)
有问题的项目很可能是 camel-spring 项目而不是 camel-spring-boot 项目。基于camel-archetype-spring启动方法隐藏在camel-spring-main依赖的org.apache.camel.spring.Main类中
默认情况下,camel-spring-main 从
META-INF/spring/
文件夹中查找 spring xml 配置文件。该应用程序可以使用 mvn camel:run
命令通过 camel-maven-plugin启动。
但是,如果你想在 camel-spring-boot 项目中运行用 xml 定义的骆驼路线,你可以将 xml 文件放置到项目中的路径
src/main/resources/camel/
。有关更多信息,您可以查看文档.
示例文件:
<?xml version="1.0" encoding="UTF-8"?>
<!-- routes.xml -->
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="test">
<from uri="timer://trigger?period=1000" />
<log message="Hello from xml" />
</route>
</routes>
该文件应仅包含路由定义,因为 camel-spring-boot-starter 负责创建和配置 CamelContext。