繁体   English   中英

如何解决Spring框架项目错误org.springframework.web.servlet.DispatcherServlet noHandlerFound?

[英]How to resolve Spring framework project error org.springframework.web.servlet.DispatcherServlet noHandlerFound?

我开始了一个用于开发后端的Spring MVC项目,该项目在这里:

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是什么意思,以及如何解决该问题? 论坛中有一个类似的帖子,但这没有帮助。

这意味着您没有控制器可以使用URI /myTest/处理请求。 在控制器中,您应该具有以下内容:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM