Spring之Resource

 Spring之所以抽象Resource接口,是因为传统的java使用URL和标准的handler来处置资源。但是有个局限是不能直接读取classpath下的资源。因此Spring定义了一套接口。这套接口分为两部分,Resource和ResourceLoader,其中是对资源的抽象,后者负责加载资源。Spring的ApplicationContext实现了ResourceLoader接口。

Resource

首先看Resource的接口定义。

public interface Resource extends InputStreamSource {
 
   boolean exists();
 
  
   boolean isReadable();
 
   /**
    * Return whether this resource represents a handle with an open
    * stream. If true, the InputStream cannot be read multiple times,
    * and must be read and closed to avoid resource leaks.
    * <p>Will be {@code false} for typical resource descriptors.
    */
   boolean isOpen();
 
   /**
    * Return a URL handle for this resource.
    * @throws IOException if the resource cannot be resolved as URL,
    * i.e. if the resource is not available as descriptor
    */
   URL getURL() throws IOException;
 
   /**
    * Return
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值