ITeye博客

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

linsky328 · 2018-01-25 10:31 · java · spring · 编程语言 · Markdown

测试环境: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"})

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。