Package org.springframework.web.context.support

# Class ServletContextResourcePatternResolver

java.lang.Object
org.springframework.core.io.support.PathMatchingResourcePatternResolver
org.springframework.web.context.support.ServletContextResourcePatternResolver

All Implemented Interfaces:
  `org.springframework.core.io.ResourceLoader`, `org.springframework.core.io.support.ResourcePatternResolver`

public class ServletContextResourcePatternResolver extends org.springframework.core.io.support.PathMatchingResourcePatternResolver
ServletContext-aware subclass of `PathMatchingResourcePatternResolver`, able to find matching resources below the web application root directory via `ServletContext.getResourcePaths(java.lang.String)`. Falls back to the superclass' file system checking for other resources.

Since:
  1.1.2
Author:
  Juergen Hoeller

## Field Summary

### Fields inherited from interface org.springframework.core.io.ResourceLoader

`CLASSPATH_URL_PREFIX`

### Fields inherited from interface org.springframework.core.io.support.ResourcePatternResolver

`CLASSPATH_ALL_URL_PREFIX`

## Constructor Summary

Constructors
Constructor
Description
`ServletContextResourcePatternResolver(ServletContext servletContext)`
Create a new ServletContextResourcePatternResolver.
`ServletContextResourcePatternResolver(org.springframework.core.io.ResourceLoader resourceLoader)`
Create a new ServletContextResourcePatternResolver.

## Method Summary

Modifier and Type
Method
Description
`protected Set<org.springframework.core.io.Resource>`
`doFindPathMatchingFileResources(org.springframework.core.io.Resource rootDirResource, String subPattern)`
Overridden version which checks for ServletContextResource and uses `ServletContext.getResourcePaths` to find matching resources below the web application root directory.
`protected void`
`doRetrieveMatchingServletContextResources(ServletContext servletContext, String fullPattern, String dir, Set<org.springframework.core.io.Resource> result)`
Recursively retrieve ServletContextResources that match the given pattern, adding them to the given result set.

### Methods inherited from class org.springframework.core.io.support.PathMatchingResourcePatternResolver

`addAllClassLoaderJarRoots, addClassPathManifestEntries, clearCache, convertClassLoaderURL, determineRootDir, doFindAllClassPathResources, doFindPathMatchingJarResources, findAllClassPathResources, findAllModulePathResources, findPathMatchingResources, getClassLoader, getJarFile, getPathMatcher, getResource, getResourceLoader, getResources, isJarResource, resolveRootDirResource, setPathMatcher, setUseCaches`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### ServletContextResourcePatternResolver

public ServletContextResourcePatternResolver(ServletContext servletContext)
Create a new ServletContextResourcePatternResolver.

Parameters:
  `servletContext` - the ServletContext to load resources with
See Also:
  - `ServletContextResourceLoader(jakarta.servlet.ServletContext)`

### ServletContextResourcePatternResolver

public ServletContextResourcePatternResolver(org.springframework.core.io.ResourceLoader resourceLoader)
Create a new ServletContextResourcePatternResolver.

Parameters:
  `resourceLoader` - the ResourceLoader to load root directories and actual resources with

## Method Details

### doFindPathMatchingFileResources

protected Set<org.springframework.core.io.Resource> doFindPathMatchingFileResources(org.springframework.core.io.Resource rootDirResource, String subPattern) throws IOException
Overridden version which checks for ServletContextResource and uses `ServletContext.getResourcePaths` to find matching resources below the web application root directory. In case of other resources, delegates to the superclass version.

Overrides:
  `doFindPathMatchingFileResources` in class `org.springframework.core.io.support.PathMatchingResourcePatternResolver`
Throws:
  `IOException`
See Also:
  - `doRetrieveMatchingServletContextResources(jakarta.servlet.ServletContext, java.lang.String, java.lang.String, java.util.Set<org.springframework.core.io.Resource>)`
  - `ServletContextResource`
  - `ServletContext.getResourcePaths(java.lang.String)`

### doRetrieveMatchingServletContextResources

protected void doRetrieveMatchingServletContextResources(ServletContext servletContext, String fullPattern, String dir, Set<org.springframework.core.io.Resource> result) throws IOException
Recursively retrieve ServletContextResources that match the given pattern, adding them to the given result set.

Parameters:
  `servletContext` - the ServletContext to work on
  `fullPattern` - the pattern to match against, with prepended root directory path
  `dir` - the current directory
  `result` - the Set of matching Resources to add to
Throws:
  `IOException` - if directory contents could not be retrieved
See Also:
  - `ServletContextResource`
  - `ServletContext.getResourcePaths(java.lang.String)`