可能的原因是测试用例未能加载应有的context配置。我们可以通过以下两种方式解决问题。
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/applicationContext.xml" })
public class DemoTest {
@Autowired
private DemoService demoService;
@Test
public void test() {
//测试代码
}
}