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

public Class WebJarsResourceResolver

extends AbstractResourceResolver
Class Inheritance
Imports
java.util.List, org.webjars.WebJarAssetLocator, reactor.core.publisher.Mono, org.springframework.core.io.Resource, org.springframework.lang.Nullable, org.springframework.web.server.ServerWebExchange

A ResourceResolver that delegates to the chain to locate a resource and then attempts to find a matching versioned resource contained in a WebJar JAR file.

This allows WebJars.org users to write version agnostic paths in their templates, like <script src="/webjars/jquery/jquery.min.js"/>. This path will be resolved to the unique version <script src="/webjars/jquery/1.2.0/jquery.min.js"/>, which is a better fit for HTTP caching and version management in applications.

This also resolves resources for version agnostic HTTP requests "GET /jquery/jquery.min.js".

This resolver requires the org.webjars:webjars-locator-core library on the classpath and is automatically registered if that library is present.

Be aware that WebJarAssetLocator constructor performs a classpath scanning that could slow down application startup.

Authors
Rossen Stoyanchev, Brian Clozel
Since
5.0
See Also
webjars.org

Field Summary

Modifier and TypeField and Description
private final WebJarAssetLocator
private static final String
private static final int
Inherited from org.springframework.web.reactive.resource.AbstractResourceResolver:
logger

Constructor Summary

AccessConstructor and Description
public
WebJarsResourceResolver()

Create a WebJarsResourceResolver with a default WebJarAssetLocator instance.

public
WebJarsResourceResolver(WebJarAssetLocator webJarAssetLocator)

Create a WebJarsResourceResolver with a custom WebJarAssetLocator instance, e.g. with a custom index.

Method Summary

Modifier and TypeMethod and Description
protected String
protected Mono<Resource>
protected Mono<String>
Inherited from org.springframework.web.reactive.resource.AbstractResourceResolver:
resolveResourceresolveUrlPath

Field Detail

webJarAssetLocatorback to summary
private final WebJarAssetLocator webJarAssetLocator
WEBJARS_LOCATIONback to summary
private static final String WEBJARS_LOCATION
WEBJARS_LOCATION_LENGTHback to summary
private static final int WEBJARS_LOCATION_LENGTH

Constructor Detail

WebJarsResourceResolverback to summary
public WebJarsResourceResolver()

Create a WebJarsResourceResolver with a default WebJarAssetLocator instance.

WebJarsResourceResolverback to summary
public WebJarsResourceResolver(WebJarAssetLocator webJarAssetLocator)

Create a WebJarsResourceResolver with a custom WebJarAssetLocator instance, e.g. with a custom index.

Method Detail

findWebJarResourcePathback to summary
protected String findWebJarResourcePath(String path)
Annotations
@Nullable
resolveResourceInternalback to summary
protected Mono<Resource> resolveResourceInternal(ServerWebExchange exchange, String requestPath, List<? extends Resource> locations, ResourceResolverChain chain)

Implements abstract org.springframework.web.reactive.resource.AbstractResourceResolver.resolveResourceInternal.

Annotations
@Override
resolveUrlPathInternalback to summary
protected Mono<String> resolveUrlPathInternal(String resourceUrlPath, List<? extends Resource> locations, ResourceResolverChain chain)

Implements abstract org.springframework.web.reactive.resource.AbstractResourceResolver.resolveUrlPathInternal.

Annotations
@Override