gpt4 book ai didi

java - 配置 Spring Boot Test 以使用单独的 bean 集

转载 作者:行者123 更新时间:2023-12-01 09:13:59 31 4
gpt4 key购买 nike

我希望我的 Spring Boot 测试在每次测试运行时都使用新的 bean 实例。我可以设置测试配置的哪一部分?

最佳答案

您可能想看一下 @DirtiesContext 注释。一旦 bean 的状态被修改,就会提供新的上下文:

有几个选项可以运行,即:

  • Before current test class: when declared at the class level with class mode set to BEFORE_CLASS
  • Before each test method in current test class: when declared at the class level with class mode set to BEFORE_EACH_TEST_METHOD
  • Before current test method: when declared at the method level with method mode set to BEFORE_METHOD
  • After current test method: when declared at the method level with method mode set to AFTER_METHOD
  • After each test method in current test class: when declared at the class level with class mode set to AFTER_EACH_TEST_METHOD
  • After current test class: when declared at the class level with class mode set to AFTER_CLASS

如需进一步阅读,请查看: http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/test/annotation/DirtiesContext.html

关于java - 配置 Spring Boot Test 以使用单独的 bean 集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40715138/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com