下面列举一些spring读取配置文件路径的代码!
包括注解形式的
配置文件放在src目录下:
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("springMVCForm-servlet.xml");
WEB-INF下:
ApplicationContext applicationContext = new FileSystemXmlApplicationContext("WebContent/WEB-INF/springMVCForm-servlet.xml");
多个文件可用*表示:
ApplicationContext applicationContext = new FileSystemXmlApplicationContext("WebContent/WEB-INF/springMVCForm-*.xml");
注解方式:
配置文件放在class目录下:
@ContextConfiguration(locations={"classpath:springMVCForm-servlet.xml"})
WEB-INF下面的
@ContextConfiguration(locations={"file:WebContent/WEB-INF/springMVCForm-servlet.xml"})