类 ResourceHandlerRegistry
- java.lang.Object
- org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
public class ResourceHandlerRegistry extends Object
Stores registrations of resource handlers for serving static resources such as images, css files and others through Spring MVC including setting cache headers optimized for efficient loading in a web browser. Resources can be served out of locations under web application root, from the classpath, and others.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.- 从以下版本开始:
- 3.1
- 作者:
- Rossen Stoyanchev
- 另请参阅:
DefaultServletHandlerConfigurer
构造器概要
构造器 构造器 说明 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 ofResourceHandlerRegistry(ApplicationContext, ServletContext, ContentNegotiationManager)
that also accepts theUrlPathHelper
used for mapping requests to static resources.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 ResourceHandlerRegistration
addResourceHandler(String... pathPatterns)
Add a resource handler for serving static resources based on the specified URL path patterns.protected AbstractHandlerMapping
getHandlerMapping()
Return a handler mapping with the mapped resource handlers; ornull
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 otherHandlerMapping
s configured in the Spring MVC application context.
构造器详细资料
ResourceHandlerRegistry
public ResourceHandlerRegistry(ApplicationContext applicationContext, ServletContext servletContext)
Create a new resource handler registry for the given application context.- 参数:
applicationContext
- the Spring application contextservletContext
- the corresponding Servlet context
ResourceHandlerRegistry
public ResourceHandlerRegistry(ApplicationContext applicationContext, ServletContext servletContext, ContentNegotiationManager contentNegotiationManager)
Create a new resource handler registry for the given application context.- 参数:
applicationContext
- the Spring application contextservletContext
- the corresponding Servlet contextcontentNegotiationManager
- the content negotiation manager to use- 从以下版本开始:
- 4.3
ResourceHandlerRegistry
public ResourceHandlerRegistry(ApplicationContext applicationContext, ServletContext servletContext, ContentNegotiationManager contentNegotiationManager, UrlPathHelper pathHelper)
A variant ofResourceHandlerRegistry(ApplicationContext, ServletContext, ContentNegotiationManager)
that also accepts theUrlPathHelper
used for mapping requests to static resources.- 从以下版本开始:
- 4.3.13
方法详细资料
addResourceHandler
public ResourceHandlerRegistration addResourceHandler(String... pathPatterns)
Add a resource handler for serving static resources based on the specified URL path patterns. The handler will be invoked for every incoming request that matches to one of the specified path patterns.Patterns like
"/static/**"
or"/css/{filename:\\w+\\.css}"
are allowed. SeeAntPathMatcher
for more details on the syntax.- 返回:
- a
ResourceHandlerRegistration
to use to further configure the registered resource handler
hasMappingForPattern
public boolean hasMappingForPattern(String pathPattern)
Whether a resource handler has already been registered for the given path pattern.
setOrder
public ResourceHandlerRegistry setOrder(int order)
Specify the order to use for resource handling relative to otherHandlerMapping
s configured in the Spring MVC application context.The default value used is
Integer.MAX_VALUE-1
.
getHandlerMapping
protected AbstractHandlerMapping getHandlerMapping()
Return a handler mapping with the mapped resource handlers; ornull
in case of no registrations.