今天在测试spring和mybatis的时候,报了找不到配置文件

java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: java.lang.IllegalArgumentException: Cannot load an ApplicationContext with a NULL 'contextLoader'. Consider annotating your test class with @ContextConfiguration or @ContextHierarchy.

以上是报错信息,后来发现。

这两句话需要加在测试类上面。

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath*:spring/applicationContext*.xml"})

以上适用于新手

原文地址:https://www.cnblogs.com/yingwangwang/p/11492582.html