Spring+Junit 读取WEB-INF上的配置文件

Spring+Junit 读取WEB-INF下的配置文件

测试环境:Spring3.0.5 + Junit4.8.1

 

配置文件放在class目录下:

ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");

 WEB-INF下:

ApplicationContext applicationContext = new FileSystemXmlApplicationContext("WebRoot/WEB-INF/spring.xml");

 

注解方式:

class:

@ContextConfiguration(locations={"classpath:spring.xml"})

 WEB-INF:

@ContextConfiguration(locations={"file:WebRoot/WEB-INF/spring.xml"}) 
我的CSDN博客地址:http://blog.csdn.net/yannanying
原文地址:https://www.cnblogs.com/yannanying/p/4342759.html