【发布时间】:2016-03-03 19:31:52
【问题描述】:
您好,我最近更新了我的 Spring Boot 应用程序并注意到新功能 (DirtiesContext.ClassMode.BEFORE_CLASS),这似乎符合我的需求,因为我在使用带注释 @RabbitListener 的方法重新加载 bean 时遇到了问题,出于某种原因 Spring 重新加载了该 bean ,但老豆被用作兔子听众。 (见here)
我的代码:
@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 {
添加 DirtiesContext.ClassMode.BEFORE_CLASS 后 Spring 停止从以下位置加载 bean 的问题:
@SpringApplicationConfiguration(classes ={ServerConfig.class,ServerThroughAMQPBrokerRabbitMQIntegrationTestConfig.class})
所以问题:
我应该如何使用 DirtiesContext.ClassMode.BEFORE_CLASS 加载 spring 上下文?
【问题讨论】:
-
我也想知道这个,因为我也有类似的问题
标签: java spring junit spring-boot