ClassPathXmlApplicationContext和FileSystemXmlApplicationContext路径问题

1.Spring中ClassPathXmlApplicationContext问题

ClassPathXmlApplicationContext是从ClassPath类加载路径下加载对应的xml文件的。

(1)一般使用classpath路径,前缀可加可不加,

例如:new ClassPathXmlApplicationContext("classpath:conf/core/train-servlet.xml")

(2)也可以使用绝对路径,加上file:表示绝对路径,一般不建议使用绝对路径

 

2. FileSystemXmlApplicationContext:

(1)用文件系统的路径,默认指定项目的根路径, src

例如:new FileSystemXmlApplicationContext("src/conf/core/train-servlet.xml")

(2)也可以使用classpath路径,这样就能读到classpath下面的相对路径,

例如:new FileSystemXmlApplicationContext("classpath:conf/core/train-servlet.xml")

(3)不需要加file: 前缀表示绝对路径,不提倡使用

1.没有盘符的是项目工作路径,即项目的根目录; src

2.有盘符表示的是文件绝对路径. D:\test\ 报错问题:

NoClassDefFoundError原因是相应的类没有找到,查看 spring.xml文件中,相应的bean时候有配置错误。

posted @ 2017-05-17 23:09  AlisonGavin  阅读(1836)  评论(0编辑  收藏  举报