No mapping found for HTTP request with URI [/index.html] in DispatcherServlet with name 'springmvc'

輸入http://localhost:8080/index.html,後臺一直報這個錯:No mapping found for HTTP request with URI [/index.html] in DispatcherServlet with name 'springmvc'

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>javademo</display-name>
  
   <!--  Spring 服務層的配置文件 -->  
    <context-param>  
        <param-name>contextConfigLocation</param-name>  
       <param-value>classpath:applicationContext.xml</param-value>   
        <!-- <param-value>/WEB-INF/applicationContext*.xml</param-value> -->
    </context-param>  
      
    <!--  Spring 容器啓動監聽器 -->  
    <listener>  
        <listener-class>org.springframework.web.context.ContextLoaderListener  
        </listener-class>  
    </listener>  
  
    <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>  
    <!--爲DispatcherServlet建立映射 -->  
    <servlet-mapping>  
        <servlet-name>springmvc</servlet-name>  
        <url-pattern>*.html</url-pattern> 
        <!--<url-pattern>/*</url-pattern>  --> 
    </servlet-mapping>  
  
  
  
  <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>
</web-app>
查了一下,這個配置文件是沒有錯的,原因是因爲java文件中少了@controller註解;

package com.netease.web.controller;

import java.util.Map;

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


@Controller
public class IndexController {
	
	@RequestMapping("index")
	public String xbsr(){
		return "index";	
	}

}





發佈了50 篇原創文章 · 獲贊 13 · 訪問量 16萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章