类 DefaultResourceLoader
- java.lang.Object
-
- com.alibaba.nacos.common.packagescan.resource.DefaultResourceLoader
-
- 所有已实现的接口:
ResourceLoader
public class DefaultResourceLoader extends java.lang.Object implements ResourceLoader
Copy from https://github.com/spring-projects/spring-framework.git, with less modifications Default implementation of theResourceLoaderinterface. Can also be used standalone.Will return a
UrlResourceif the location value is a URL, and aClassPathResourceif it is a non-URL path or a "classpath:" pseudo-URL.- 从以下版本开始:
- 10.03.2004
- 作者:
- Juergen Hoeller
-
-
嵌套类概要
嵌套类 修饰符和类型 类 说明 protected static classDefaultResourceLoader.ClassPathContextResourceClassPathResource that explicitly expresses a context-relative path through implementing the ContextResource interface.
-
字段概要
字段 修饰符和类型 字段 说明 private java.lang.ClassLoaderclassLoaderprivate java.util.Set<ProtocolResolver>protocolResolversprivate java.util.Map<java.lang.Class<?>,java.util.Map<Resource,?>>resourceCaches-
从接口继承的字段 com.alibaba.nacos.common.packagescan.resource.ResourceLoader
CLASSPATH_URL_PREFIX
-
-
构造器概要
构造器 构造器 说明 DefaultResourceLoader()Create a new DefaultResourceLoader.DefaultResourceLoader(java.lang.ClassLoader classLoader)Create a new DefaultResourceLoader.
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidaddProtocolResolver(ProtocolResolver resolver)Register the given resolver with this resource loader, allowing for additional protocols to be handled.voidclearResourceCaches()Clear all resource caches in this resource loader.java.lang.ClassLoadergetClassLoader()Return the ClassLoader to load class path resources with.java.util.Collection<ProtocolResolver>getProtocolResolvers()Return the collection of currently registered protocol resolvers, allowing for introspection as well as modification.ResourcegetResource(java.lang.String location)Return aResourcehandle for the specified resource location.protected ResourcegetResourceByPath(java.lang.String path)Return a Resource handle for the resource at the given path.<T> java.util.Map<Resource,T>getResourceCache(java.lang.Class<T> valueType)Obtain a cache for the given value type, keyed byResource.voidsetClassLoader(java.lang.ClassLoader classLoader)Specify the ClassLoader to load class path resources with, ornullfor using the thread context class loader at the time of actual resource access.
-
-
-
字段详细资料
-
classLoader
private java.lang.ClassLoader classLoader
-
protocolResolvers
private final java.util.Set<ProtocolResolver> protocolResolvers
-
resourceCaches
private final java.util.Map<java.lang.Class<?>,java.util.Map<Resource,?>> resourceCaches
-
-
构造器详细资料
-
DefaultResourceLoader
public DefaultResourceLoader()
Create a new DefaultResourceLoader.ClassLoader access will happen using the thread context class loader at the time of actual resource access (since 5.3). For more control, pass a specific ClassLoader to
DefaultResourceLoader(ClassLoader).- 另请参阅:
Thread.getContextClassLoader()
-
DefaultResourceLoader
public DefaultResourceLoader(java.lang.ClassLoader classLoader)
Create a new DefaultResourceLoader.- 参数:
classLoader- the ClassLoader to load class path resources with, ornullfor using the thread context class loader at the time of actual resource access
-
-
方法详细资料
-
setClassLoader
public void setClassLoader(java.lang.ClassLoader classLoader)
Specify the ClassLoader to load class path resources with, ornullfor 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 5.3).
-
getClassLoader
public java.lang.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(onlynullif even the systemClassLoaderisn't accessible) - 另请参阅:
ClassPathResource
-
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.
- 从以下版本开始:
- 4.3
- 另请参阅:
getProtocolResolvers()
-
getProtocolResolvers
public java.util.Collection<ProtocolResolver> getProtocolResolvers()
Return the collection of currently registered protocol resolvers, allowing for introspection as well as modification.- 从以下版本开始:
- 4.3
-
getResourceCache
public <T> java.util.Map<Resource,T> getResourceCache(java.lang.Class<T> valueType)
Obtain a cache for the given value type, keyed byResource.- 参数:
valueType- the value type, e.g. an ASMMetadataReader- 返回:
- the cache
Map, shared at theResourceLoaderlevel - 从以下版本开始:
- 5.0
-
clearResourceCaches
public void clearResourceCaches()
Clear all resource caches in this resource loader.- 从以下版本开始:
- 5.0
- 另请参阅:
getResourceCache(java.lang.Class<T>)
-
getResource
public Resource getResource(java.lang.String location)
从接口复制的说明:ResourceLoaderReturn aResourcehandle 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
Resourcehandle does not imply an existing resource; you need to invokeResource.exists()to check for existence.- 指定者:
getResource在接口中ResourceLoader- 参数:
location- the resource location- 返回:
- a corresponding
Resourcehandle (nevernull) - 另请参阅:
ResourceLoader.CLASSPATH_URL_PREFIX,Resource.exists(),InputStreamSource.getInputStream()
-
getResourceByPath
protected Resource getResourceByPath(java.lang.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
- 另请参阅:
ClassPathResource
-
-