Using spring typically configures Url-pattern AS/, instead of a Web server servlet becomes the default servlet, static resources are inaccessible, add <MVC: Default-servlet-handler/> The servlet for the specified Web server is the default servlet, and the static resources are accessible. Access to the @RequestMapping("/model") was not accessible at that time.
The reason is: when < /> , the framework registers annotaitonmethodhandleradapter This bean, can handle ; configure <mvc:default-servlet-handler/> , the framework registered Handleradapter cannot process @RequestMapping , the controller cannot be found. There are several solutions to the solution:
One, add <MVC:ANNOTATION-DRIVEN/> configuration, after you add this configuration, The framework automatically registers requestma Span style= "Color:rgb (57,51,255); Font-family:monaco;" >ppinghandlermapping and (spring3.1 later version), you can process @RequestMapping .
Two, do not use @requestmapping, directly specify the control class, manual < = "/hello" = "Com.niuwolfs.controller.HelloController " /> Registration
Public class Hellocontroller implements controller{
@Override
Public Modelandview HandleRequest (httpservletrequest req, HttpServletResponse resp) throws Exception {
Modelandview mv = new modelandview ();
MV . AddObject ("msg", "Hello Spring mvc!" );
mv. Setviewname ("Hello");
return mv;
}
}
Iii. Manual registration of requestmappinghandlermapping and requestmappinghandleradapter
<!--Spring3.1 After using this type of configuration handler Mapping-
< Bean class=" Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping "/>
<!--Spring3.1 After using this type of configuration handler Adapter-
< Bean class=" Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter "/>
Four, do not configure the <mvc:default-servlet-handler/>, the spring Url-pattern configured as. Do, will not replace the Web service's default servlet, However, access to the controller must be matched with the configured. Do and so on.
Spring MVC Default-servlet-handler and Annotation-driven configuration