Class WebJarsResourceResolver
- java.lang.Object
- org.springframework.web.servlet.resource.AbstractResourceResolver
- org.springframework.web.servlet.resource.WebJarsResourceResolver
- All Implemented Interfaces:
ResourceResolver
public class WebJarsResourceResolver extends AbstractResourceResolver
AResourceResolver
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="/jquery/jquery.min.js"/>
. This path will be resolved to the unique version<script src="/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" library on classpath, and is automatically registered if that library is present.
- Since:
- 4.2
- Author:
- Brian Clozel
- See Also:
ResourceChainRegistration
, webjars.org
Field Summary
Fields inherited from class org.springframework.web.servlet.resource.AbstractResourceResolver
logger
Constructor Summary
Constructors Constructor Description WebJarsResourceResolver()
Create aWebJarsResourceResolver
with a defaultWebJarAssetLocator
instance.WebJarsResourceResolver(org.webjars.WebJarAssetLocator webJarAssetLocator)
Create aWebJarsResourceResolver
with a customWebJarAssetLocator
instance, e.g.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
findWebJarResourcePath(String path)
protected Resource
resolveResourceInternal(HttpServletRequest request, String requestPath, List<? extends Resource> locations, ResourceResolverChain chain)
protected String
resolveUrlPathInternal(String resourceUrlPath, List<? extends Resource> locations, ResourceResolverChain chain)
Methods inherited from class org.springframework.web.servlet.resource.AbstractResourceResolver
resolveResource, resolveUrlPath
Constructor Detail
WebJarsResourceResolver
public WebJarsResourceResolver()
Create aWebJarsResourceResolver
with a defaultWebJarAssetLocator
instance.
WebJarsResourceResolver
public WebJarsResourceResolver(org.webjars.WebJarAssetLocator webJarAssetLocator)
Create aWebJarsResourceResolver
with a customWebJarAssetLocator
instance, e.g. with a custom index.- Since:
- 4.3
Method Detail
resolveResourceInternal
protected Resource resolveResourceInternal(HttpServletRequest request, String requestPath, List<? extends Resource> locations, ResourceResolverChain chain)
- Specified by:
resolveResourceInternal
in classAbstractResourceResolver
resolveUrlPathInternal
protected String resolveUrlPathInternal(String resourceUrlPath, List<? extends Resource> locations, ResourceResolverChain chain)
- Specified by:
resolveUrlPathInternal
in classAbstractResourceResolver
findWebJarResourcePath
protected String findWebJarResourcePath(String path)