---
title: "Spring Junit 读取WEB-INF下的配置文件"
author: "linsky328"
date: "2018-01-25T10:31:44Z"
tags: []
categories: ["编程语言"]
slug: "spring-junit-web-inf"
draft: false
lastmod: "2018-01-25T10:31:33Z"
id: 2408998
url: "https://linsky328.iteye.com/blog/2408998"
---

测试环境:Spring3.0.5 + Junit4.8.1
 
配置文件放在class目录下：
 view plain copy
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");  
WEB-INF下：
 
 view plain copy
ApplicationContext applicationContext = new FileSystemXmlApplicationContext("WebRoot/WEB-INF/spring.xml");  
 
多个文件可用*表示
 view plain copy
ApplicationContext applicationContext = new FileSystemXmlApplicationContext("WebRoot/WEB-INF/spring-*.xml");  
 
注解方式：
 
class：
 view plain copy
@ContextConfiguration(locations={"classpath:spring.xml"})  
WEB-INF：
 view plain copy
@ContextConfiguration(locations={"file:WebRoot/WEB-INF/spring.xml"})