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

public Class WebJarsResourceResolver

extends AbstractResourceResolver
Class Inheritance
Imports
java.util.List, jakarta.servlet.http.HttpServletRequest, org.webjars.WebJarAssetLocator, org.springframework.core.io.Resource, org.springframework.lang.Nullable

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.

Author
Brian Clozel
Since
4.2
See Also
org.springframework.web.servlet.config.annotation.ResourceChainRegistration, 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.servlet.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 Resource
protected String
Inherited from org.springframework.web.servlet.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.

Since
4.3

Method Detail

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

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

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

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

Annotations
@Override
@Nullable