Class DefaultServletHandlerConfigurer
- java.lang.Object
- org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer
public class DefaultServletHandlerConfigurer extends Object
Configures a request handler for serving static resources by forwarding the request to the Servlet container's "default" Servlet. This is intended to be used when the Spring MVCDispatcherServlet
is mapped to "/" thus overriding the Servlet container's default handling of static resources.Since this handler is configured at the lowest precedence, effectively it allows all other handler mappings to handle the request, and if none of them do, this handler can forward it to the "default" Servlet.
- Since:
- 3.1
- Author:
- Rossen Stoyanchev, Juergen Hoeller
- See Also:
DefaultServletHttpRequestHandler
Constructor Summary
Constructors Constructor Description DefaultServletHandlerConfigurer(ServletContext servletContext)
Create aDefaultServletHandlerConfigurer
instance.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected SimpleUrlHandlerMapping
buildHandlerMapping()
Return a handler mapping instance ordered atOrdered.LOWEST_PRECEDENCE
containing theDefaultServletHttpRequestHandler
instance mapped to"/**"
; ornull
if default servlet handling was not been enabled.void
enable()
Enable forwarding to the "default" Servlet.void
enable(String defaultServletName)
Enable forwarding to the "default" Servlet identified by the given name.
Constructor Detail
DefaultServletHandlerConfigurer
public DefaultServletHandlerConfigurer(ServletContext servletContext)
Create aDefaultServletHandlerConfigurer
instance.- Parameters:
servletContext
- the ServletContext to use.
Method Detail
enable
public void enable()
Enable forwarding to the "default" Servlet.When this method is used the
DefaultServletHttpRequestHandler
will try to autodetect the "default" Servlet name. Alternatively, you can specify the name of the default Servlet viaenable(String)
.- See Also:
DefaultServletHttpRequestHandler
enable
public void enable(@Nullable String defaultServletName)
Enable forwarding to the "default" Servlet identified by the given name.This is useful when the default Servlet cannot be autodetected, for example when it has been manually configured.
- See Also:
DefaultServletHttpRequestHandler
buildHandlerMapping
@Nullable protected SimpleUrlHandlerMapping buildHandlerMapping()
Return a handler mapping instance ordered atOrdered.LOWEST_PRECEDENCE
containing theDefaultServletHttpRequestHandler
instance mapped to"/**"
; ornull
if default servlet handling was not been enabled.- Since:
- 4.3.12