spring的4个获取资源总结

 1.ClassPathResource
说明:使用ClassPathResource,只能直接使用:hello.xml,而:
(1)不能用src/hello.xml,
(2)不能用classpath前缀,如classpath:hello.xml,或classpath:src/hello.xml
(3)不能用绝对路径。

2.FileSystemResource

说明:使用FileSystemResource,
(1)使用:src/hello.xml,而不能使用classpath:前缀如
classpath:src/hello.xml,或classpath:hello.xml
(2)使用绝对路径,但不能用前缀file:
3.ClassPathXmlApplicationContext
说明:使用ClassPathXmlApplicationContext
(1)classpath: 前缀可要可不要的, 默认就是指项目的classpath路径下面;但是不能用src/hello.xml,或classpath:src/hello.xml
(2)如果要使用绝对路径,需要加上 file: 前缀表示这是绝对路径;注意,一定要加上file:

4.FileSystemXmlApplicationContext

说明:使用FileSystemXmlApplicationContext,默认表示的是两种:
(1)没有盘符的是项目工作路径,即项目的根目录;不能写hello.xml,要写src/hello.xml
(2)有盘符表示的是 文件绝对路径:file:前缀可要可不要
(3)如果要使用classpath路径,需要前缀classpath,但是加上classpath則不能加上src/否则报错。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值