Class ResourceHandlerRegistry
To create a resource handler, use addResourceHandler(String...)
providing the URL path patterns for which the handler should be invoked to
serve static resources (for example, "/resources/**").
Then use additional methods on the returned
ResourceHandlerRegistration to add one or more locations from which
to serve static content from (for example, {"/",
"classpath:/META-INF/public-web-resources/"}) or to specify a cache
period for served resources.
- Since:
- 3.1
- Author:
- Rossen Stoyanchev
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionResourceHandlerRegistry(ApplicationContext applicationContext, jakarta.servlet.ServletContext servletContext) Create a new resource handler registry for the given application context.ResourceHandlerRegistry(ApplicationContext applicationContext, jakarta.servlet.ServletContext servletContext, @Nullable ContentNegotiationManager contentNegotiationManager) Create a new resource handler registry for the given application context.ResourceHandlerRegistry(ApplicationContext applicationContext, jakarta.servlet.ServletContext servletContext, @Nullable ContentNegotiationManager contentNegotiationManager, @Nullable UrlPathHelper pathHelper) Deprecated, for removal: This API element is subject to removal in a future version. -
Method Summary
Modifier and TypeMethodDescriptionaddResourceHandler(String... pathPatterns) Add a resource handler to serve static resources.protected @Nullable AbstractHandlerMappingReturn a handler mapping with the mapped resource handlers; ornullin case of no registrations.booleanhasMappingForPattern(String pathPattern) Whether a resource handler has already been registered for the given path pattern.setOrder(int order) Specify the order to use for resource handling relative to otherHandlerMappingsconfigured in the Spring MVC application context.
-
Constructor Details
-
ResourceHandlerRegistry
public ResourceHandlerRegistry(ApplicationContext applicationContext, jakarta.servlet.ServletContext servletContext) Create a new resource handler registry for the given application context.- Parameters:
applicationContext- the Spring application contextservletContext- the corresponding Servlet context
-
ResourceHandlerRegistry
public ResourceHandlerRegistry(ApplicationContext applicationContext, jakarta.servlet.ServletContext servletContext, @Nullable ContentNegotiationManager contentNegotiationManager) Create a new resource handler registry for the given application context.- Parameters:
applicationContext- the Spring application contextservletContext- the corresponding Servlet contextcontentNegotiationManager- the content negotiation manager to use- Since:
- 4.3
-
ResourceHandlerRegistry
@Deprecated(since="7.0", forRemoval=true) public ResourceHandlerRegistry(ApplicationContext applicationContext, jakarta.servlet.ServletContext servletContext, @Nullable ContentNegotiationManager contentNegotiationManager, @Nullable UrlPathHelper pathHelper) Deprecated, for removal: This API element is subject to removal in a future version.A variant ofResourceHandlerRegistry(ApplicationContext, ServletContext, ContentNegotiationManager)that also accepts theUrlPathHelperused for mapping requests to static resources.- Since:
- 4.3.13
-
-
Method Details
-
addResourceHandler
Add a resource handler to serve static resources. The handler is invoked for requests that match one of the specified URL path patterns.Patterns such as
"/static/**"or"/css/{filename:\\w+\\.css}"are supported.For pattern syntax see
PathPatternwhen parsed patterns areenabledorAntPathMatcherotherwise. The syntax is largely the same withPathPatternmore tailored for web usage and more efficient. -
hasMappingForPattern
Whether a resource handler has already been registered for the given path pattern. -
setOrder
Specify the order to use for resource handling relative to otherHandlerMappingsconfigured in the Spring MVC application context.The default value used is
Integer.MAX_VALUE-1. -
getHandlerMapping
Return a handler mapping with the mapped resource handlers; ornullin case of no registrations.
-
ResourceHandlerRegistry(ApplicationContext, ServletContext, ContentNegotiationManager)