2016-02-12 75 views
0

我開始一個Spring MVC項目開發後端,該項目是在這裏:如何解決Spring框架項目錯誤org.springframework.web.servlet.DispatcherServlet noHandlerFound?

https://github.com/Chaklader/backend 

這只是初始化,我收到以下錯誤,

Feb 12, 2016 2:23:42 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound 
WARNING: No mapping found for HTTP request with URI [/myTest/] in DispatcherServlet with name 'offers' 

裏面的WEB-INF文件夾,該web.xml文件是如下,

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> 
    <display-name>MyBackend</display-name> 
    <welcome-file-list> 
    <welcome-file>index.html</welcome-file> 
    <welcome-file>index.htm</welcome-file> 
    <welcome-file>index.jsp</welcome-file> 
    <welcome-file>default.html</welcome-file> 
    <welcome-file>default.htm</welcome-file> 
    <welcome-file>default.jsp</welcome-file> 
    </welcome-file-list> 

    <servlet> 
    <description></description> 
    <display-name>offers</display-name> 
    <servlet-name>offers</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
    <servlet-name>offers</servlet-name> 
    <url-pattern>/</url-pattern> 
    </servlet-mapping> 
</web-app> 

和,offers-servlet.xml文件(也,內第ËWEB-INF文件夾),如下圖所示

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    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.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd 
     http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> 

    <context:component-scan base-package="com.backend.test.controllers"></context:component-scan> 
    <mvc:annotation-driven></mvc:annotation-driven> 
<bean id="jspViewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="prefix" value="/WEB-INF/JSP/"></property> 
    <property name="suffix" value=".jsp"></property> 
    </bean> 
</beans> 

是什麼意思noHandlerFound以及如何解決這個問題呢?論壇中有一個類似的帖子,但是,這並沒有幫助。

+1

服務器URL模式應該是'/ *':'/*' – jny

+0

我只是想,這並沒有解決問題。 – Arefe

回答

1

這意味着你沒有一個控制器來處理與URI /myTest/的請求。 在你的控制器,你應該有這樣的:

@RequestMapping("/myTest") 
public String myTest(){ 
    return "viewName"; 
} 
+0

我遵循你的建議,還有,在運行服務器之前更新maven(apache tomcat v8.0)。我仍然得到同樣的錯誤。你有第二個想法嗎? – Arefe

+1

你的項目似乎並不是有效的maven項目。它不應該包含WebContent文件夾。相反,它應該有一個用於Java類的'src/main/java',以及'src/main/webapp /',其中包含web stuff。 – isah

+0

我創建了一個動態web項目,後來轉換爲maven項目,添加了依賴關係並做了maven更新。它以前工作,但現在不工作。 – Arefe

相關問題