今天在配置SpringMVC時,訪問項目一直出現404,沒法訪問。web
報錯:spring
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.spring-mvc
調試了一下,發現沒有到達controller層裏面。mvc
運行後沒有到達controller層的解決方法:app
1.檢查web.xml文件中的SpringMVC的配置是否正確。async
<!-- Spring MVC servlet --> <servlet> <servlet-name>SpringMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <!--<init-param>表示啓動時初始化的配置文件--> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> <async-supported>true</async-supported> </servlet> <servlet-mapping> <!--<servlet-mapping>中的</servlet-name>必須與<servlet>裏面的<servlet-name>保持一致--> <servlet-name>SpringMVC</servlet-name> <!-- 通常定義爲 / ,表示全部請求都經過DispatcherServlet來處理--> <url-pattern>/</url-pattern> </servlet-mapping>
2.檢查spring-mvc.xml,是否添加了註解驅動url
<!--註解驅動--> <mvc:annotation-driven/>