5.6. Spring Boot 的 BOM 文件
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.5.0.fuse-sb2-750029-redhat-00003</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.5.0.fuse-750029-redhat-00002</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 环境进行了优化的方式进行打包。