类 DefaultResourceLoader

java.lang.Object
cn.taketoday.core.io.DefaultResourceLoader
所有已实现的接口:
ResourceLoader
直接已知子类:
ClassRelativeResourceLoader, FileSystemResourceLoader

public class DefaultResourceLoader extends Object implements ResourceLoader
Default implementation of the ResourceLoader interface.

Will return a UrlResource if the location value is a URL, and a ClassPathResource if it is a non-URL path or a "classpath:" pseudo-URL.

从以下版本开始:
4.0
作者:
Juergen Hoeller, TODAY 2021/10/7 17:06
  • 字段详细资料

  • 构造器详细资料

    • DefaultResourceLoader

      public DefaultResourceLoader()
      Create a new DefaultResourceLoader.

      ClassLoader access will happen using the thread context class loader at the time of actual resource access. For more control, pass a specific ClassLoader to DefaultResourceLoader(ClassLoader).

      另请参阅:
    • DefaultResourceLoader

      public DefaultResourceLoader(@Nullable ClassLoader classLoader)
      Create a new DefaultResourceLoader.
      参数:
      classLoader - the ClassLoader to load class path resources with, or null for using the thread context class loader at the time of actual resource access
  • 方法详细资料

    • setClassLoader

      public void setClassLoader(@Nullable ClassLoader classLoader)
      Specify the ClassLoader to load class path resources with, or null for using the thread context class loader at the time of actual resource access.

      The default is that ClassLoader access will happen using the thread context class loader at the time of actual resource access (since 4.0).

    • getClassLoader

      @Nullable public ClassLoader getClassLoader()
      Return the ClassLoader to load class path resources with.

      Will get passed to ClassPathResource's constructor for all ClassPathResource objects created by this resource loader.

      指定者:
      getClassLoader 在接口中 ResourceLoader
      返回:
      the ClassLoader (only null if even the system ClassLoader isn't accessible)
      另请参阅:
    • addProtocolResolver

      public void addProtocolResolver(ProtocolResolver resolver)
      Register the given resolver with this resource loader, allowing for additional protocols to be handled.

      Any such resolver will be invoked ahead of this loader's standard resolution rules. It may therefore also override any default rules.

      另请参阅:
    • getProtocolResolvers

      @Nullable public Collection<ProtocolResolver> getProtocolResolvers()
      Return the collection of currently registered protocol resolvers, allowing for introspection as well as modification.
      另请参阅:
    • getResourceCache

      public <T> Map<Resource,T> getResourceCache(Class<T> valueType)
      Obtain a cache for the given value type, keyed by Resource.
      参数:
      valueType - the value type, e.g. an ASM MetadataReader
      返回:
      the cache Map, shared at the ResourceLoader level
    • clearResourceCaches

      public void clearResourceCaches()
      Clear all resource caches in this resource loader.
      另请参阅:
    • getResource

      public Resource getResource(String location)
      从接口复制的说明: ResourceLoader
      Return a Resource handle for the specified resource location.

      The handle should always be a reusable resource descriptor, allowing for multiple InputStreamSource.getInputStream() calls.

      • Must support fully qualified URLs, e.g. "file:C:/test.dat".
      • Must support classpath pseudo-URLs, e.g. "classpath:test.dat".
      • Should support relative file paths, e.g. "WEB-INF/test.dat". (This will be implementation-specific, typically provided by an ApplicationContext implementation.)

      Note that a Resource handle does not imply an existing resource; you need to invoke Resource.exists() to check for existence.

      指定者:
      getResource 在接口中 ResourceLoader
      参数:
      location - the resource location
      返回:
      a corresponding Resource handle (never null)
      另请参阅:
    • getResourceByPath

      protected Resource getResourceByPath(String path)
      Return a Resource handle for the resource at the given path.

      The default implementation supports class path locations. This should be appropriate for standalone implementations but can be overridden, e.g. for implementations targeted at a Servlet container.

      参数:
      path - the path to the resource
      返回:
      the corresponding Resource handle
      另请参阅: