在进行web开发的时候,一般咱们都会使用Spring框架,使用spring容器管理java bean。 而spring的配置文件有时候放在classpath下面,有时候放在WEB-INF下面。java
通常在开发的过程当中都须要对开发完的方法进行单元测试,而单元测试须要使用到注解,就须要使用web
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:spring-context.xml"})spring
两个注解加载spring配置文件。框架
关于spring配置文件路径的写法,若是spring-context.xml文件放在classpath下面,这种写法是对的单元测试
可是若是放在了WEB-INF,即不是classpath下,怎么引用呢?测试
须要从文件系统加载,使用file开头:spa
@ContextConfiguration(locations={"file:WebRoot/WEB-INF/spring-context.xml"})xml
就能够加载成功!!!开发