类 ResourceHandlerRegistration
- 从以下版本开始:
- 4.0 2022/2/15 17:06
- 作者:
- Rossen Stoyanchev, Keith Donald, Brian Clozel, Harry Yang
-
字段概要
字段修饰符和类型字段说明private CacheControlprivate Integerprivate final List<cn.taketoday.core.io.Resource>(专用程序包) HttpRequestHandlerprivate booleanprivate final String[]private ResourceChainRegistrationprivate boolean -
构造器概要
构造器构造器说明ResourceHandlerRegistration(String... pathPatterns) Create aResourceHandlerRegistrationinstance. -
方法概要
修饰符和类型方法说明addResourceLocations(cn.taketoday.core.io.Resource... locations) Configure locations to serve static resources from based on pre-resolvedResourcereferences.addResourceLocations(String... locations) Add one or more resource locations from which to serve static content.protected String[]Return the URL path patterns for the resource handler.protected ResourceHttpRequestHandlerReturn aResourceHttpRequestHandlerinstance.notFoundHandler(HttpRequestHandler notFoundHandler) Set not found handlerresourceChain(boolean cacheResources) Configure a chain of resource resolvers and transformers to use.resourceChain(boolean cacheResources, cn.taketoday.cache.Cache cache) Configure a chain of resource resolvers and transformers to use.setCacheControl(CacheControl cacheControl) Specify theCacheControlwhich should be used by the resource handler.setCachePeriod(Integer cachePeriod) Specify the cache period for the resources served by the resource handler, in seconds.setOptimizeLocations(boolean optimizeLocations) Set whether to optimize the specified locations through an existence check on startup, filtering non-existing directories upfront so that they do not have to be checked on every resource access.setUseLastModified(boolean useLastModified) Set whether theResource.lastModified()information should be used to drive HTTP responses.
-
字段详细资料
-
pathPatterns
-
locationValues
-
locationsResources
-
cachePeriod
-
cacheControl
-
resourceChainRegistration
-
useLastModified
private boolean useLastModified -
optimizeLocations
private boolean optimizeLocations -
notFoundHandler
-
-
构造器详细资料
-
ResourceHandlerRegistration
Create aResourceHandlerRegistrationinstance.- 参数:
pathPatterns- one or more resource URL path patterns
-
-
方法详细资料
-
addResourceLocations
Add one or more resource locations from which to serve static content. Each location must point to a valid directory. Multiple locations may be specified as a comma-separated list, and the locations will be checked for a given resource in the order specified.For example, {
"/","classpath:/META-INF/public-web-resources/"} allows resources to be served both from the web application root and from any JAR on the classpath that contains a/META-INF/public-web-resources/directory, with resources in the web application root taking precedence.For
URL-based resources(e.g. files, HTTP URLs, etc) this method supports a special prefix to indicate the charset associated with the URL so that relative paths appended to it can be encoded correctly, e.g.[charset=Windows-31J]https://example.org/path.- 返回:
- the same
ResourceHandlerRegistrationinstance, for chained method invocation
-
addResourceLocations
Configure locations to serve static resources from based on pre-resolvedResourcereferences.- 参数:
locations- the resource locations to use- 返回:
- the same
ResourceHandlerRegistrationinstance, for chained method invocation
-
setCachePeriod
Specify the cache period for the resources served by the resource handler, in seconds. The default is to not send any cache headers but to rely on last-modified timestamps only. Set to 0 in order to send cache headers that prevent caching, or to a positive number of seconds to send cache headers with the given max-age value.- 参数:
cachePeriod- the time to cache resources in seconds- 返回:
- the same
ResourceHandlerRegistrationinstance, for chained method invocation
-
setCacheControl
Specify theCacheControlwhich should be used by the resource handler.Setting a custom value here will override the configuration set with
setCachePeriod(java.lang.Integer).- 参数:
cacheControl- the CacheControl configuration to use- 返回:
- the same
ResourceHandlerRegistrationinstance, for chained method invocation
-
setUseLastModified
Set whether theResource.lastModified()information should be used to drive HTTP responses.This configuration is set to
trueby default.- 参数:
useLastModified- whether the "last modified" resource information should be used- 返回:
- the same
ResourceHandlerRegistrationinstance, for chained method invocation - 另请参阅:
-
setOptimizeLocations
Set whether to optimize the specified locations through an existence check on startup, filtering non-existing directories upfront so that they do not have to be checked on every resource access.The default is
false, for defensiveness against zip files without directory entries which are unable to expose the existence of a directory upfront. Switch this flag totruefor optimized access in case of a consistent jar layout with directory entries.- 参数:
optimizeLocations- whether to optimize the locations through an existence check on startup- 返回:
- the same
ResourceHandlerRegistrationinstance, for chained method invocation - 另请参阅:
-
resourceChain
Configure a chain of resource resolvers and transformers to use. This can be useful, for example, to apply a version strategy to resource URLs.If this method is not invoked, by default only a simple
PathResourceResolveris used in order to match URL paths to resources under the configured locations.- 参数:
cacheResources- whether to cache the result of resource resolution; setting this to "true" is recommended for production (and "false" for development, especially when applying a version strategy)- 返回:
- the same
ResourceHandlerRegistrationinstance, for chained method invocation
-
resourceChain
public ResourceChainRegistration resourceChain(boolean cacheResources, cn.taketoday.cache.Cache cache) Configure a chain of resource resolvers and transformers to use. This can be useful, for example, to apply a version strategy to resource URLs.If this method is not invoked, by default only a simple
PathResourceResolveris used in order to match URL paths to resources under the configured locations.- 参数:
cacheResources- whether to cache the result of resource resolution; setting this to "true" is recommended for production (and "false" for development, especially when applying a version strategycache- the cache to use for storing resolved and transformed resources; by default aConcurrentMapCacheis used. Since Resources aren't serializable and can be dependent on the application host, one should not use a distributed cache but rather an in-memory cache.- 返回:
- the same
ResourceHandlerRegistrationinstance, for chained method invocation
-
notFoundHandler
Set not found handlerhandle resource not found
- 参数:
notFoundHandler- HttpRequestHandler
-
getPathPatterns
Return the URL path patterns for the resource handler. -
getRequestHandler
Return aResourceHttpRequestHandlerinstance.
-