【问题标题】:Spring Batch Integration Test with MongoDB使用 MongoDB 进行 Spring 批量集成测试
【发布时间】:2021-05-11 07:55:51
【问题描述】:

这里的文档使用 jdbc 模板。 https://docs.spring.io/spring-batch/docs/4.1.x/reference/html/testing.html#testing

我想问一下如何使用 MongoDB 编写与 Spring Batch 的集成测试?最好,如果你们能提供一个具体的例子。

我将这些依赖项用于您的信息

  <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
  </dependency>
  <dependency>
         <groupId>de.flapdoodle.embed</groupId>
         <artifactId>de.flapdoodle.embed.mongo</artifactId>
         <scope>test</scope>
  </dependency>
 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-batch</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.batch</groupId>
            <artifactId>spring-batch-test</artifactId>
            <version>${spring.batch.version}</version>
            <scope>test</scope>
        </dependency>

【问题讨论】:

  • 你应该尝试至少写一些代码,即使它在开始时不起作用。
  • 如果我能找到一个使用 mongodb 的 spring 批处理示例就好了

标签: java spring-boot unit-testing spring-batch batch-processing


【解决方案1】:

要是我能找到一个使用 mongodb 的 spring 批处理示例就好了

您可以在此处找到从 MongoDB 读取/写入数据的作业示例:https://github.com/spring-projects/spring-batch/tree/master/spring-batch-samples#mongodb-sample

示例代码在这里:https://github.com/spring-projects/spring-batch/blob/master/spring-batch-samples/src/main/java/org/springframework/batch/sample/mongodb/MongoDBSampleApp.java

如果您打算针对 MongoDB 编写集成测试,可以使用 flapdoodle.embed.mongotestcontainers

【讨论】:

  • 一如既往的感谢!
猜你喜欢
  • 1970-01-01
  • 2019-02-27
  • 2018-02-01
  • 2015-08-12
  • 1970-01-01
  • 2020-08-10
  • 2021-06-01
  • 2020-07-24
  • 1970-01-01
相关资源
最近更新 更多