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时候有配置错误。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM