如何在 spring 引导中的每次测试 class 后销毁和重新创建 bean
How to destroy and recreate bean after each test class in spring boot
我有一个应用程序,我在其中创建 bean A,它安排配置中定义的任务,但在测试中,我想在每次测试 class 之前创建它,并在每次 class 之后销毁。
我需要它,因为我更新每个 class 中的属性,例如:
@TestPropertySource(properties = ["my.property=valueForTest"])
JUnit/Spring可以吗?
我知道唯一的选择是通过 @DirtiesContext
丢弃整个上下文。这显然也扔掉了你的豆子。
我有一个应用程序,我在其中创建 bean A,它安排配置中定义的任务,但在测试中,我想在每次测试 class 之前创建它,并在每次 class 之后销毁。
我需要它,因为我更新每个 class 中的属性,例如:
@TestPropertySource(properties = ["my.property=valueForTest"])
JUnit/Spring可以吗?
我知道唯一的选择是通过 @DirtiesContext
丢弃整个上下文。这显然也扔掉了你的豆子。