Created an empty SPRINGMVC project, Tomcat can start normally, but when it runs, it never enters the controller and reports 404 errors. Most of it is because the scan package is not configured.
eg
Web. XML is as follows:
<?XML version= "1.0" encoding= "UTF-8"?><Web-appXmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns= "Http://java.sun.com/xml/ns/javaee"xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"version= "3.0"> <servlet> <Servlet-name>Springmvc</Servlet-name> <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class> <Init-param> <Param-name>Contextconfiglocation</Param-name> <Param-value>/web-inf/springmvc-servlet.xml</Param-value> </Init-param> <Load-on-startup>1</Load-on-startup> </servlet> <servlet-mapping> <Servlet-name>Springmvc</Servlet-name> <Url-pattern>/</Url-pattern> </servlet-mapping> <welcome-file-list> <Welcome-file>Index.html</Welcome-file> <Welcome-file>index.jsp</Welcome-file> </welcome-file-list></Web-app>
Springmvc-servlet.xml
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns:p= "http://www.springframework.org/schema/p"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:mvc= "Http://www.springframework.org/schema/mvc"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-3.0.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/co Ntext/spring-context-3.0.xsd Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/m Vc/spring-mvc-3.0.xsd "> <!--support for default annotation mappings - <Mvc:annotation-driven/> <!--automatic scanning of all class files in the directory - <Context:component-scanBase-package= "Com.myspringmvc.controller.*" /> <!--parsing the name of the model view - <BeanID= "Viewresolver"class= "Org.springframework.web.servlet.view.InternalResourceViewResolver"> < Propertyname= "prefix"value= "/web-inf/jsp/" /> < Propertyname= "suffix"value= ". jsp" /> </Bean></Beans>
Testcontroller.java
package Com.myspringmvc.controller; import Org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import Org.springframework.web.bind.annotation.RequestMethod; @Controller public class TestController {@RequestM Apping (Value = "/test", Method={requestmethod.get,requestmethod.post}) public String Test () { return "test" ; }}
Visit page:
The solution is as follows:
<!--- <base-package = " com.myspringmvc.controller.* "/>----instead of---- >>>><!-- - <base-package = " Com.myspringmvc.controller "/>
Content from: http://www.cnblogs.com/likun10579/p/5342562.html
Everyone to pick up-springmvc in tomcat normal start, always access controller, out of 404 wrong