一般Log4j配置在web.xml中,在单元测试时,不需要启动Tomcat,所有Log4j找不到配置文件
在测试类中手动加载 配置文件
PropertyConfigurator.configure("src/main/webapp/WEB-INF/log4j.properties");
DOMConfigurator.configure("src/main/webapp/WEB-INF/log4j.xml");
参数相对与项目 目录
单元测试整合Srping使用注解
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({ "classpath*:/applicationContext.xml",
"classpath*:/applicationUntil_Config.xml",
"classpath*:/spring-datasource.xml" })