First of all, we all know that Springmvc has two mappers:
Org.springframework.web.servlet.handler. beannameurlhandlermapping
And
Org.springframework.web.servlet.handler. simpleurlhandlermapping
And the first "name URL mapper" is used by default.
There are two types of mappers that can coexist .
But when the project was built today, when the two mappers were enabled,beannameurlhandlermapping failed.
Here is my XML configuration:
<BeanID= "Hello"name= "/hello.action"class= "servlet." Hello "></Bean> <BeanID= "Yaha"class= "servlet." Yaha "></Bean> <BeanID= "Update"class= "servlet." Update "></Bean> <Beanclass= "Org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> < Propertyname= "Mappings"> <Props> <propKey= "/update.action">Update</prop> <propKey= "/yaha.action">Yaha</prop> </Props> </ Property> </Bean>
Operation result :
Access to Update.action ———— Normal
Access to Yaha.action ———— Normal
Visit Hello.action ———— 404
It is obvious that the "Name URL" Mapper failed to match.
Analysis :
Failure is just the default one, and usually we use the default mapper is often not to write the mapper's <bean> declaration , and today declare a mapper, then all the mappings may be all to the declaration of the one. So the default mapper is no longer called.
Test :
Add the following declaration to the XML:
<class= "Org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" ></ Bean >
Access to Update.action ———— Normal
Access to Yaha.action ———— Normal
Access to Hello.action ———— Normal
Conclusion :
do not forget to declare the default beannameurlhandlermapping when it is necessary to use both mappers . (It is best to declare it even if you use default only)
About the two kinds of mapper in SPRINGMVC cannot coexist