相关疑难解决方法(0)

使用@DirtiesContext BEFORE_CLASS进行Spring启动测试

您好我最近更新了我的spring启动应用程序并注意到了新功能(DirtiesContext.ClassMode.BEFORE_CLASS),这似乎符合我的需要,因为我遇到了使用方法注释@RabbitListener重新加载bean的问题,出于某种原因Spring重新加载了那个bean,但是旧的豆子正在用作兔子听众.(见这里)

我的代码:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes ={ServerConfig.class,ServerThroughAMQPBrokerRabbitMQIntegrationTestConfig.class})
@Category({IntegrationTest.class})
@TestPropertySource("classpath:test.properties")
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
@TestExecutionListeners(listeners = {DirtiesContextBeforeModesTestExecutionListener.class, DirtiesContextTestExecutionListener.class})
public class ServerThroughAMQPBrokerRabbitMQIntegrationTest {
Run Code Online (Sandbox Code Playgroud)

添加DirtiesContext.ClassMode.BEFORE_CLASS Spring之后的问题将停止从以下位置加载bean:

@SpringApplicationConfiguration(classes ={ServerConfig.class,ServerThroughAMQPBrokerRabbitMQIntegrationTestConfig.class})
Run Code Online (Sandbox Code Playgroud)

所以问题:

我应该如何使用DirtiesContext.ClassMode.BEFORE_CLASS加载spring上下文?

java junit spring spring-boot

4
推荐指数
1
解决办法
4542
查看次数

标签 统计

java ×1

junit ×1

spring ×1

spring-boot ×1