使注解@ContextConfiguration同时支持locations和classes

@Configuration
@ImportResource("classpath:META-INF/dataContext.xml")
class TestConfig {
}

And, in your test code use the following:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {Configuration.class, TestConfig.class})
@ActiveProfiles("test")
public class CityDaoImplTest { ... }
原文地址:https://www.cnblogs.com/haorui/p/9175023.html