public class ResourceHandlerRegistry extends Object
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.
DefaultServletHandlerConfigurer
Constructor and Description |
---|
ResourceHandlerRegistry(ApplicationContext applicationContext,
ServletContext servletContext)
Create a new resource handler registry for the given application context.
|
ResourceHandlerRegistry(ApplicationContext applicationContext,
ServletContext servletContext,
ContentNegotiationManager contentNegotiationManager)
Create a new resource handler registry for the given application context.
|
ResourceHandlerRegistry(ApplicationContext applicationContext,
ServletContext servletContext,
ContentNegotiationManager contentNegotiationManager,
UrlPathHelper pathHelper)
A variant of
ResourceHandlerRegistry(ApplicationContext, ServletContext, ContentNegotiationManager)
that also accepts the UrlPathHelper used for mapping requests to static resources. |
Modifier and Type | Method and Description |
---|---|
ResourceHandlerRegistration |
addResourceHandler(String... pathPatterns)
Add a resource handler to serve static resources.
|
protected AbstractHandlerMapping |
getHandlerMapping()
Return a handler mapping with the mapped resource handlers; or
null in case
of no registrations. |
boolean |
hasMappingForPattern(String pathPattern)
Whether a resource handler has already been registered for the given path pattern.
|
ResourceHandlerRegistry |
setOrder(int order)
Specify the order to use for resource handling relative to other
HandlerMappings
configured in the Spring MVC application context. |
public ResourceHandlerRegistry(ApplicationContext applicationContext, ServletContext servletContext)
applicationContext
- the Spring application contextservletContext
- the corresponding Servlet contextpublic ResourceHandlerRegistry(ApplicationContext applicationContext, ServletContext servletContext, @Nullable ContentNegotiationManager contentNegotiationManager)
applicationContext
- the Spring application contextservletContext
- the corresponding Servlet contextcontentNegotiationManager
- the content negotiation manager to usepublic ResourceHandlerRegistry(ApplicationContext applicationContext, ServletContext servletContext, @Nullable ContentNegotiationManager contentNegotiationManager, @Nullable UrlPathHelper pathHelper)
ResourceHandlerRegistry(ApplicationContext, ServletContext, ContentNegotiationManager)
that also accepts the UrlPathHelper
used for mapping requests to static resources.public ResourceHandlerRegistration addResourceHandler(String... pathPatterns)
Patterns such as "/static/**"
or "/css/{filename:\\w+\\.css}"
are supported.
For pattern syntax see PathPattern
when parsed patterns
are enabled
or
AntPathMatcher
otherwise. The syntax is largely the same with
PathPattern
more tailored for web usage and more efficient.
public boolean hasMappingForPattern(String pathPattern)
public ResourceHandlerRegistry setOrder(int order)
HandlerMappings
configured in the Spring MVC application context.
The default value used is Integer.MAX_VALUE-1
.
@Nullable protected AbstractHandlerMapping getHandlerMapping()
null
in case
of no registrations.