package org.springframework.core.io;
import org.springframework.lang.Nullable;
import org.springframework.util.ResourceUtils;
/**
* 加载资源的策略接口 (例如,类路径或文件系统资源).
* 需要一个{@link org.springframework.context.ApplicationContext}来提供此功能
* 以及扩展的{@link.org.springframebook.core.io.support.ResourcePatternResolver}支持。
*
* <p>{@link DefaultResourceLoader} 是一个独立的实现,可在ApplicationContext之外使用,
* 也可由{@link ResourceEditor}使用。
*
* <p>在ApplicationContext中运行时,可以使用特定上下文的资源加载策略,
* 从字符串填充类型为{@code Resource}和{@code Resource[]}的Bean属性。
*
* @author Juergen Hoeller
* @since 10.03.2004
* @see Resource
* @see org.springframework.core.io.support.ResourcePatternResolver
* @see org.springframework.context.ApplicationContext
* @see org.springframework.context.ResourceLoaderAware
*/
public interface ResourceLoader {
/** 从类路径加载的伪URL前缀: "classpath:". */
String CLASSPATH_URL_PREFIX = ResourceUtils.CLASSPATH_URL_PREFIX;
/**
* 返回指定资源位置的{@code Resource}句柄。
* <p>句柄应该始终是可重用的资源描述符,允许多个{@link Resource#getInputStream()}调用。
* <p><ul>
* <li>必须支持完全限定的URL,例如“file:C:/test.dat”。
* <li>必须支持classpath的伪URL,例如“classpath:test.dat”。
* <li>应支持相对文件路径,例如“WEB-INF/test.dat”。(这将是特定于实现的,通常由ApplicationContext实现提供。)
* </ul>
* <p>请注意,{@code Resource}句柄并不意味着存在资源;您需要调用{@link Resource#exists}来检查是否存在。
* @param location 资源位置
* @return 对应的{@code Resource}句柄(不为{@code null})
* @see #CLASSPATH_URL_PREFIX
* @see Resource#exists()
* @see Resource#getInputStream()
*/
Resource getResource(String location);
/**
* 使用 {@code ResourceLoader} 暴露 {@link ClassLoader} 。
* <p>需要直接访问{@code ClassLoader}的客户端可以使用{@code ResourceLoader}以统一的方式进行访问,
* 而不依赖于线程上下文{@code Class Loader}。
* @return {@code ClassLoader} (仅当系统{@code ClassLoader}无法访问时才使用{@code null})
* @see org.springframework.util.ClassUtils#getDefaultClassLoader()
* @see org.springframework.util.ClassUtils#forName(String, ClassLoader)
*/
@Nullable
ClassLoader getClassLoader();
}
【spring-core】ResourceLoader
最新推荐文章于 2025-05-06 10:13:36 发布