Top Description Fields Constructors Methods
org.springframework.web.reactive.config

public Class ResourceHandlerRegistry

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Arrays, .LinkedHashMap, .List, .Map, org.springframework.beans.factory.BeanInitializationException, org.springframework.core.Ordered, org.springframework.core.io.ResourceLoader, org.springframework.lang.Nullable, org.springframework.web.reactive.handler.AbstractUrlHandlerMapping, .SimpleUrlHandlerMapping, org.springframework.web.reactive.resource.ResourceTransformer, .ResourceTransformerSupport, .ResourceUrlProvider, .ResourceWebHandler, org.springframework.web.server.WebHandler

Stores registrations of resource handlers for serving static resources such as images, css files and others through Spring WebFlux including setting cache headers optimized for efficient loading in a web browser. Resources can be served out of locations under web application root, from the classpath, and others.

To create a resource handler, use addResourceHandler(String...) providing the URL path patterns for which the handler should be invoked to serve static resources (e.g. "/resources/**").

Then use additional methods on the returned ResourceHandlerRegistration to add one or more locations from which to serve static content from (e.g. {"/", "classpath:/META-INF/public-web-resources/"}) or to specify a cache period for served resources.

Authors
Rossen Stoyanchev, Brian Clozel
Since
5.0

Field Summary

Modifier and TypeField and Description
private int
private final List<ResourceHandlerRegistration>
private final ResourceLoader
private ResourceUrlProvider

Constructor Summary

AccessConstructor and Description
public
ResourceHandlerRegistry(ResourceLoader
the resource loader to use
resourceLoader
)

Create a new resource handler registry for the given resource loader (typically an application context).

Method Summary

Modifier and TypeMethod and Description
public ResourceHandlerRegistration

Returns:

a ResourceHandlerRegistration to use to further configure the registered resource handler
addResourceHandler
(String... patterns)

Add a resource handler for serving static resources based on the specified URL path patterns.

protected AbstractUrlHandlerMapping
getHandlerMapping()

Return a handler mapping with the mapped resource handlers; or null in case of no registrations.

private ResourceWebHandler
public boolean
hasMappingForPattern(String pathPattern)

Whether a resource handler has already been registered for the given path pattern.

public ResourceHandlerRegistry
setOrder(int order)

Specify the order to use for resource handling relative to other HandlerMappings configured in the Spring configuration.

public void
setResourceUrlProvider(ResourceUrlProvider
the resource URL provider to use
resourceUrlProvider
)

Configure the ResourceUrlProvider that can be used by org.springframework.web.reactive.resource.ResourceTransformer instances.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

orderback to summary
private int order
registrationsback to summary
private final List<ResourceHandlerRegistration> registrations
resourceLoaderback to summary
private final ResourceLoader resourceLoader
resourceUrlProviderback to summary
private ResourceUrlProvider resourceUrlProvider
Annotations
@Nullable

Constructor Detail

ResourceHandlerRegistryback to summary
public ResourceHandlerRegistry(ResourceLoader resourceLoader)

Create a new resource handler registry for the given resource loader (typically an application context).

Parameters
resourceLoader:ResourceLoader

the resource loader to use

Method Detail

addResourceHandlerback to summary
public ResourceHandlerRegistration addResourceHandler(String... patterns)

Add a resource handler for serving static resources based on the specified URL path patterns. The handler will be invoked for every incoming request that matches to one of the specified path patterns.

Patterns like "/static/**" or "/css/{filename:\\w+\\.css}" are allowed. See org.springframework.web.util.pattern.PathPattern for more details on the syntax.

Returns:ResourceHandlerRegistration

a ResourceHandlerRegistration to use to further configure the registered resource handler

getHandlerMappingback to summary
protected AbstractUrlHandlerMapping getHandlerMapping()

Return a handler mapping with the mapped resource handlers; or null in case of no registrations.

Annotations
@Nullable
getRequestHandlerback to summary
private ResourceWebHandler getRequestHandler(ResourceHandlerRegistration registration)
hasMappingForPatternback to summary
public boolean hasMappingForPattern(String pathPattern)

Whether a resource handler has already been registered for the given path pattern.

setOrderback to summary
public ResourceHandlerRegistry setOrder(int order)

Specify the order to use for resource handling relative to other HandlerMappings configured in the Spring configuration.

The default value used is Integer.MAX_VALUE-1.

setResourceUrlProviderback to summary
public void setResourceUrlProvider(ResourceUrlProvider resourceUrlProvider)

Configure the ResourceUrlProvider that can be used by org.springframework.web.reactive.resource.ResourceTransformer instances.

Parameters
resourceUrlProvider:ResourceUrlProvider

the resource URL provider to use

Since
5.0.11