ClassPathXmlApplicationContext:
(1)一般使用classpath路径,前缀可加可不加,例如:new ClassPathXmlApplicationContext("classpath:conf/core/train-servlet.xml")
(2)也可以使用绝对路径,加上file:表示绝对路径,一般不建议使用绝对路径
FileSystemXmlApplicationContext:
(1)用文件系统的路径,默认指定项目的根路径,例如:new FileSystemXmlApplicationContext("src/conf/core/train-servlet.xml")
(2)也可以使用classpath路径,这样就能读到classpath下面的相对路径,例如:new FileSystemXmlApplicationContext("classpath:conf/core/train-servlet.xml")
(3)不需要加file:前缀表示绝对路径,不提倡使用
附:
classpath路径的获取:
(1)Thread.currentThread().getContextClassLoader().getResource("").getPath()
(2)TestClass.class.getClassLoader().getResource("").getPath() (TestClass为src某一个包中的类)