《spring设计思想》23-ResourceLoader资源加载

本文介绍了Spring中的ResourceLoader,它是资源加载的工具类,用于将Resource加载到Spring中。ResourceLoader接口包含获取资源和ClassLoader的方法,其中getResource的location参数支持file、classpath和WEB-INF等格式。主要的实现类包括ClassPathResource和FileSystemResource。举例说明了DefaultResourceLoader和FileSystemResourceLoader如何加载当前用户目录下的文件。
摘要由CSDN通过智能技术生成

上一节简单的介绍了一下spring中的资源体系设计,最终的抽象类型是Resource,能够获取输入流和文件信息。

这一节总结一下资源加载起ResourceLoader。

所谓资源加载器,就是把上一节讲到的Resource加载到spring中用到的工具类,在spring中被设计为ResourceLoader。

简单的看下ResourceLoader接口


/**
 * Strategy interface for loading resources (e.. class path or file system
 * resources).
 * <p>Bean properties of type Resource and Resource array can be populated
 * from Strings when running in an ApplicationContext, using the particular
 * context's resource loading strategy.
 */
public interface ResourceLoader {

	/** Pseudo URL prefix for loading from the class path: "classpath:" */
	String CLASSPATH_URL_PREFIX = ResourceUtils.CLASSPATH_URL_PREFIX;


	/**
	 * Return a Resource handle for the specified resource location.
	 * <li>Must support fully qualified URLs, e.g. "file:C:/test.dat".
	 * <li>Mus
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值