文档菜单
文档首页
/ / /
Java反应式流驱动程序
/

下载和安装

1

请确保您已安装以下内容JDK版本8或更高版本 在您的开发环境中。

本指南向您展示如何使用Maven或Gradle在集成开发环境(IDE)中添加MongoDB Java驱动依赖项。我们建议您使用IntelliJ IDEA或Eclipse IDE等IDE。IDE使配置Maven或Gradle以构建和运行您的项目更加方便。

如果您不使用IDE,请参阅构建Maven创建新的Gradle构建以获取有关如何设置项目的更多信息。请参阅 MongoDB Reactive Streams Driver直接从Maven下载驱动程序和依赖项。

2

本指南使用基于 Reactive Streams 规范的 Reactor 库中的方法。

在您的 IDE 中打开一个新的 Maven 或 Gradle 项目。如果您使用 Maven,请将以下片段添加到您的pom.xml:

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-bom</artifactId>
<version>2023.0.7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

然后,将以下内容添加到您的 pom.xml 依赖列表中

<dependencies>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

要使用Gradle安装Reactor,请参阅获取Reactor项目Reactor文档中的“获取Reactor”部分。

配置完依赖项后,通过运行依赖管理器并刷新您的IDE中的项目来确保它们对项目可用。

3

在您的项目中,如果您正在使用Maven,请将以下内容添加到您的pom.xml依赖项列表中

<dependencies>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-reactivestreams</artifactId>
<version>5.2.1</version>
</dependency>
</dependencies>

如果您正在使用Gradle,请将以下内容添加到您的build.gradle依赖项列表中

dependencies {
implementation 'org.mongodb:mongodb-driver-reactivestreams:5.2.1'
}

配置完依赖项后,通过运行依赖管理器并刷新您的IDE中的项目来确保它们对项目可用。

完成这些步骤后,您将有一个新项目,并且已安装驱动依赖项。

注意

如果在这一步遇到问题,请在MongoDB 社区论坛寻求帮助或通过使用页面右上角或右下角的评价此页面标签提交反馈。

返回

开始使用