java - What does configureDefaultServletHandling means? -
i trying understand how spring mvc works, , don't understand part of code in spring configurations:
@override public void configuredefaultservlethandling(defaultservlethandlerconfigurer configurer) { configurer.enable(); }
when in webcontextapplication
class, works fine , when it's not present works fine too. purpose of method? should webcontextapplication
class have method? , why?
as jb nizet tried explain both used serve static resources.
so question java based spring configuration has
@override public void addresourcehandlers(resourcehandlerregistry registry) { registry.addresourcehandler("/assets/**").addresourcelocations("/resources/bootstrap/"); }
then why need
@override public void configuredefaultservlethandling(defaultservlethandlerconfigurer configurer) { configurer.enable(); }
or why <mvc:default-servlet-handler/>
if have
<mvc:resources mapping="/assets/**" location="/resources/bootstrap/" />
in terms of xml configuration.
to answer question based on requirements have put don't need override configuredefaultservlethandling()
have overridden , provided static resource mappings.
by overriding addresourcehandlers()
method asking resourcehttprequesthandler
serve resources mentioned resource location.
however if override configuredefaultservlethandling()
, enabling asking default servlet (mapped "/") serve resources. there couple of things need take care here if using this. quoting docs -
this allows mapping dispatcherservlet "/" (thus overriding mapping of container’s default servlet), while still allowing static resource requests handled container’s default servlet. configures defaultservlethttprequesthandler url mapping of "/**" , lowest priority relative other url mappings.
this handler forward requests default servlet. therefore important remains last in order of other url handlermappings. case if use or alternatively if setting own customized handlermapping instance sure set order property value lower of defaultservlethttprequesthandler, integer.max_value.
Comments
Post a Comment