当活动配置文件为“test”时使用嵌入式 MongoDB

mip*_*mip 5 spring integration-testing mongodb spring-boot

我有

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

在我的 pom.xml 中,因此我的 Spring Boot 应用程序在启动时尝试连接到本地主机上的 MongoDB。

我也有

<dependency>
  <groupId>de.flapdoodle.embed</groupId>
  <artifactId>de.flapdoodle.embed.mongo</artifactId>
  <scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

因此,当我运行单元测试时,会使用嵌入式 MongoDb。

出于集成测试的目的,如果应用程序是使用“测试”活动配置文件启动的,我还想使用嵌入式 MongoDB。

因此,我想有效地删除<scope>test</scope>嵌入依赖项,并在活动配置文件为“测试”时使用嵌入版本。

我怎样才能实现这个目标?