When using the SPRINGMVC framework, it was found that some configurations were handlermapping, and some did not, so what is the difference? Do not configure the normal use of the framework?
Let's take a look at what the framework uses when you don't configure any handlermapping.
Here we comment out the code for configuring Handlermapping in the framework
<?XML version= "1.0" encoding= "UTF-8"?>2<Beansxmlns= "Http://www.springframework.org/schema/beans"3 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns:p= "http://www.springframework.org/schema/p"4 Xmlns:mvc= "Http://www.springframework.org/schema/mvc"Xmlns:context= "Http://www.springframework.org/schema/context"5 xsi:schemalocation= "6 Http://www.springframework.org/schema/beans 7 http://www.springframework.org/schema/beans/spring- Beans.xsd 8 Http://www.springframework.org/schema/context 9 http://www.springframework.org/schema/context/ SPRING-CONTEXT.XSD10 Http://www.springframework.org/schema/mvc11 Http://www.springframework.org/schema/mvc /spring-mvc.xsd "> the<Context:component-scanBase-package= "Com.springmvc.demo.controller" /> from<!--<bean class= "org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>16 <bean class= "Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/> - -<!--<mvc:default-servlet-handler/> - -<!--<mvc:annotation-driven/> - +<!--<mvc:resources location= "/resource/images/" mapping= "/images/**"/> - -<BeanID= "/simplecontroller"class= "Com.springmvc.demo.controller.SimpleController"></Bean> the<!--<bean class= "org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" >23 </bean> - the<Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver"> -< Propertyname= "Viewclass"value= "Org.springframework.web.servlet.view.JstlView" /> -< Propertyname= "prefix"value="/" /> -< Propertyname= "suffix"value= ". jsp" /> in</Bean> from</Beans>
This time we hit a breakpoint and debug it and see what handlermapping is used:
You can see that you have registered two handlermapping, so:
1. Access/simplecontroller, Normal
2. Access to/user/preadduser (via @requestmapping annotations) is also normal, as defaultannotationhandlermapping can also handle annotations, This is still a class before spring3.1 processing annotations, 3.1 and later changed to requestmappinghandlermapping this class, the view API can see this class "has expired", the default continues to use this class may be for backwards compatibility.
In fact, this is a default configuration, Position in the Spring-webmvc.jar, if you do not explicitly register a handlermapping, then you will use org.springframework.web.servlet.DispatcherServlet.properties this inside the default Configuration, the configuration is as follows:
org.springframework.web.servlet.handlermapping= Org.springframework.web.servlet.handler.beannameurlhandlermapping,\
Org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping
Therefore, the above two requestmapping will be registered.
SPRINGMVC notes-Do not configure handlermapping