搜索

5.6. Spring Boot 的 BOM 文件

download PDF

Maven Bill of Materials (BOM) 文件的目的是提供一组可正常工作的 Maven 依赖项版本,从而防止您必须为每个 Maven 工件单独定义版本。

重要

确保您基于您使用的 Spring Boot 版本(Spring Boot 1 或 Spring Boot 2)使用正确的 Fuse BOM。

Spring Boot 的 Fuse BOM 提供以下优点:

  • 定义 Maven 依赖项的版本,以便在将依赖项添加到 POM 时不需要指定版本。
  • 定义一组对特定版本的 Fuse 经过全面测试并支持的策展依赖关系。
  • 简化 Fuse 的升级。
重要

红帽仅支持由 Fuse BOM 定义的一组依赖项。

5.6.1. 合并 BOM 文件

要将 BOM 文件合并到 Maven 项目中,请在项目的 pom.xml 文件中指定 dependencies Management 元素(或者,可能在父 POM 文件中),如下面的 Spring Boot 2 和 Spring Boot 1 示例所示:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project ...>
  ...
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <!-- configure the versions you want to use here -->
    <fuse.version>7.6.0.fuse-sb2-760028-redhat-00001</fuse.version>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.jboss.redhat-fuse</groupId>
        <artifactId>fuse-springboot-bom</artifactId>
        <version>${fuse.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  ...
</project>


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project ...>
  ...
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <!-- configure the versions you want to use here -->
    <fuse.version>7.6.0.fuse-760027-redhat-00001</fuse.version>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.jboss.redhat-fuse</groupId>
        <artifactId>fuse-springboot-bom</artifactId>
        <version>${fuse.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  ...
</project>

使用依赖项管理机制指定 BOM 后,可以在不指定工件版本 的情况下 向 POM 添加 Maven 依赖项。例如,要为 camel-hystrix 组件添加依赖项,您可以在 POM 中的 dependencies 元素中添加以下 XML 片段:

<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-hystrix-starter</artifactId>
</dependency>

请注意,Camel 工件 ID 如何通过 -starter 后缀,将 Camel Hystrix 组件指定为 camel-hystrix-starter,而不是 camel-hystrix。Camel 初学者组件以针对 Spring Boot 环境进行了优化的方式进行打包。

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

© 2024 Red Hat, Inc.