Spring mvc资源不起作用

Ale*_*lex 1 spring spring-mvc java-ee

我使用Eclipse Luna创建了一个简单的Spring MVC项目,但是如果我在springConfig-servlet.xml中添加mvc:resources,它就无法工作.我在Tomcat中有这个错误:

 PM org.springframework.web.servlet.PageNotFound noHandlerFound
Avvertenza: No mapping found for HTTP request with URI [/SpringStore/] in   DispatcherServlet with name 'springConfig'
Run Code Online (Sandbox Code Playgroud)

我哪里做错了?谢谢

这是我项目的结构

在此输入图像描述

Web.xml代码

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns: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" id="WebApp_ID" version="3.0">
<display-name>SpringStore</display-name>

<servlet>
  <servlet-name>springConfig</servlet-name>
  <servlet-class> org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
  <servlet-name>springConfig</servlet-name>
   <url-pattern>/</url-pattern> 
</servlet-mapping> 
</web-app>
Run Code Online (Sandbox Code Playgroud)

springConfig-Servlet代码:

<?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"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd">

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
</bean>

<context:component-scan base-package="controller"/>
<mvc:resources mapping="/resources/**" location="/resources/"/>
</beans>
Run Code Online (Sandbox Code Playgroud)

HomeController.java

package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class HomeController {

@RequestMapping(value="/",method=RequestMethod.GET)
public String welcome(){
    return "index";     
}//welcome

}
Run Code Online (Sandbox Code Playgroud)

文件index.jsp的内容很长,我不在这里写.

RE3*_*350 6

我认为你在springConfig-Servlet.xml文件中缺少下面的条目.

<mvc:default-servlet-handler />
<mvc:annotation-driven />
Run Code Online (Sandbox Code Playgroud)