第 1 章 Camel Spring Boot 入门


本指南介绍了 Camel Spring Boot,并演示了如何开始使用 Camel Spring Boot 构建应用程序:

1.1. Camel Spring Boot Starters

对 Spring Boot 的 Camel 支持为许多 Camel 组件提供 Camel 和启动器的 自动配置。Camel 上下文的提示自动配置会在 Spring 上下文中自动检测 Camel 路由,并将密钥 Camel 实用程序(如制作者模板、消费者模板和类型转换器)注册为 Bean。

注意

有关使用 Maven archtype 为 Spring Boot 应用程序生成 Camel 的详情,请参考使用 Maven 生成 Camel for Spring Boot 应用程序

首先,您必须将 Camel Spring Boot BOM 添加到 Maven pom.xml 文件中。

<dependencyManagement>

    <dependencies>
        <!-- Camel BOM -->
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-spring-boot-bom</artifactId>
            <version>3.14.5.redhat-00032</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <!-- ... other BOMs or dependencies ... -->
    </dependencies>

</dependencyManagement>
Copy to Clipboard Toggle word wrap

camel-spring-boot-bom 是包含 Camel Spring Boot starter JAR 列表的基本 BOM。

接下来,添加 Camel Spring Boot 启动程序 以启动 Camel 上下文

    <dependencies>
        <!-- Camel Starter -->
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-spring-boot-starter</artifactId>
        </dependency>
        <!-- ... other dependencies ... -->
    </dependencies>
Copy to Clipboard Toggle word wrap

您还必须添加 Spring Boot 应用程序所需的任何组件启动程序。下例演示了如何将 自动配置初学者 添加到 ActiveMQ 组件

    <dependencies>
        <!-- ... other dependencies ... -->
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-activemq-starter</artifactId>
        </dependency>
    </dependencies>
Copy to Clipboard Toggle word wrap

curated camel-spring-boot-dependencies BOM (生成)包含 Spring Boot 和 Apache Camel 使用调整的 JAR,以避免任何冲突。此 BOM 用于测试 camel-spring-boot 本身。

Spring Boot 用户可以选择使用 Camel 依赖项,方法是使用 camel-spring-boot-bom,该依赖项只有 Camel 启动器 JAR 作为受管依赖项。但是,如果来自 Spring Boot 的第三方 JAR 与特定的 Camel 组件不兼容,这可能会导致类路径冲突。

1.1.2. Spring Boot 配置支持

每个 初学者 都列出了您可以在标准 application.propertiesapplication.yml 文件中配置的配置参数。这些参数的格式为 camel.component.[component-name].[parameter]。例如,配置 ActiveMQ 代理的 URL,您可以设置:

camel.component.activemq.broker-url=tcp://localhost:61616
Copy to Clipboard Toggle word wrap

1.1.3. 添加 Camel 路由

在 Spring 应用程序上下文中检测到 Camel 路由,例如,将带有 org.springframework.stereotype.Component 标注的路由,添加到 Camel 上下文中并运行。

import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;

@Component
public class MyRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        from("...")
            .to("...");
    }

}
Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat