在使用Eclispe作为开发工具时,用spring框架,外加Junit4测试spring框架的代码是非常常见的事情。

问题:在配置正确的情况下启动报初始化错误。

配置如下:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath*:/config/spring-context.xml"})
public class FlightDateCorrectionProcessorTest {


@Test
public void test() {
System.out.println("hw");
}

}

spring-context.xml配置确认无误的情况下,启动Junit Test. 报错如下:

Eclipse spring junit 4 测试 报java.lang.ExceptionInInitializerError

分析:1.是不是缺jar包?

           引入hamcrest 包后仍然如上错误

         2.看看详细日志:

         2.1 拷贝trace 信息

Eclipse spring junit 4 测试 报java.lang.ExceptionInInitializerError

2.2粘贴在空文本处:

Eclipse spring junit 4 测试 报java.lang.ExceptionInInitializerError

 发现是junit版本过低导致的,查看自己的pom文件;

            <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>

</dependency>

2.3 修改为2.12后重新运行,启动成功。

相关文章: