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>

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>

然后您可以使用 Camel 路由添加类,例如:

package com.example;

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

@Component
public class MyRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        from("timer:foo").to("log:bar");
    }
}

这些路由将自动启动。

您可以在 application.propertiesapplication.yml 文件中自定义 Camel 应用程序。

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

© 2024 Red Hat, Inc.