I have an integration test class annotated as follows
@WebAppConfiguration
@ContextConfiguration(classes = {AppConfiguration.class})
@RunWith(SpringJUnit4ClassRunner.class)
public class CacheConsumerTest {
}
Here's my AppConfiguration
@Configuration
@ComponentScan(basePackages = {"com.etc.etc.etc."})
@EnableWebMvc
public class AppConfiguration {
}
For some reason, none of my @Component
beans' @PreDestroy
is getting called at the end of all tests in CacheConsumerTest
. @PostConstruct
is however being called at the start, before any tests are run.
Anyone know what the problem may be? Some of my @Component
are background threads that I would like to have shut off (by having its @Predestroy called), otherwise the work they do in the background will cause subsequent tests in other test classes to fail.
I've tried adding @DirtiesContext(classMode=ClassMode.AFTER_CLASS)
but it didn't help.
EDIT: Figured out the problem, I had to do an additional step to make DirtiesContext work: Does Spring @DirtiesContext reload Spring context?