1.2. Spring Boot
Spring Boot 会自动配置 Camel。Spring 上下文中提供的 Camel 上下文自动探测 Camel 路由的评论性自动配置,并将主要 Camel 实用程序(如制作者模板、消费者模板和类型转换器)注册为 Bean。
Maven 用户需要在其 pom.xml
中添加以下依赖项才能使用这个组件:
<dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-spring-boot</artifactId> <version>3.14.2.redhat-00054</version> <!-- use the same version as your Camel core version --> </dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot</artifactId>
<version>3.14.2.redhat-00054</version> <!-- use the same version as your Camel core version -->
</dependency>
Camel -spring-boot
jar 附带了 spring.factories
文件,因此当您将依赖项添加到类路径时,Spring Boot 会自动为您配置 Camel。
1.2.1. Camel Spring Boot Starter 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Apache Camel 附带了一个 Spring Boot Starter 模块,它允许您使用入门程序开发 Spring Boot 应用程序。源代码中也有 示例应用程序。
要使用 starter,请在 spring boot pom.xml 文件中添加以下内容:
<dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-spring-boot-bom</artifactId> <version>3.14.2.redhat-00054</version> <!-- use the same version as your Camel core version --> </dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-bom</artifactId>
<version>3.14.2.redhat-00054</version> <!-- use the same version as your Camel core version -->
</dependency>
然后您可以使用 Camel 路由添加类,例如:
这些路由将自动启动。
您可以在 application.properties
或 application.yml
文件中自定义 Camel 应用程序。