SPRINGMVC notes-Do not configure handlermapping

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.