is default handler mapping is overridden when we c

2019-06-13 17:32发布

问题:

I want to know is default handler mapping created by spring mvc framework override if we create our custom handler mapping. I have doubt because i created custom handler mapping in two projects in one

  1. BeanNameHandlerMapping
  2. SimpleUrlHandlerMapping is injected in dispatcher servlet but in another one these are not registered in dispatcher servlet

I am using different version of spring 3 framework for these two project. Is it because of version change in spring 3

I am not getting default handler mapping in spring 3.0 but getting in spring 3 higher version

Thanks

回答1:

Specify the order of your custom HandlerMapping to have the lowest int value so that it gets tried first over the other registered HandlerMappings.

Explanation

Figuring out the available HandlerMappings in the web context is part of the DispatcherServlet initialisation:

That method, is discovering all the registered HandlerMappings and as you can see it is sorting them based on their defined order.

Otherwise it is falling back on the default handlerMapping: the BeanNameUrlHandlerMapping