No mapping found for HTTP request with UR

今天搭建spring mvc的系统,成功启动后无法访问,提示如下:

No mapping found for HTTP request with URI [/admin/log.do] in DispatcherServlet 。

原因:<context:component-scan base-package="com.ecp.web"/> 这一段必须写在*-servlet.xml文件中。否则就算你在配置文件中引入了所有的头文件,spring都不会管你长得多好看!

 

警示:如果我们的项目采用了springMVC,那么,组件扫描、mybatis的dao扫描最好都在这个 *-servlet.xml中指定。不然就会出现在启动时找不到Bean.

 

 

 

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

    <mvc:annotation-driven />
    <!-- 多个以逗号分隔 -->
	<context:component-scan base-package="com.ecp.web"/>
	<mvc:resources location="/ext-3.0.0/**" mapping="/ext-3.0.0/" />
	<mvc:resources location="/ecpres/**" mapping="/ecpres/" />
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		 <property name="viewClass"    value="org.springframework.web.servlet.view.JstlView" />  
		<property name="prefix" value="/WEB-INF/pages/"></property>
		<property name="suffix" value=".jsp"></property>
	</bean>
    <!--扫描自动注入DAO  -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
   		 <!-- 多个以逗号分隔 -->
        <property name="basePackage" value="com.ecp.web.dao" />
    </bean>
</beans>

  

 

 

 

 

 

For myself: 添加新的模块,必须在*-servlet.xml配置文件中 配置controller的路径 、services的路径 ,以及mybatis的dao路径 。

展开阅读全文

No mapping found for HTTP request with URI in DispatcherServlet

03-21

在做一个springMVC项目的时候,遇到了这种问题。在网上看了好多总是无法解决。rnweb.xml代码如下:rn[code=html]rnrn mvcrn rn index.htmlrn index.htmrn index.jsprn default.htmlrn default.htmrn default.jsprn rn rn springMVCrn org.springframework.web.servlet.DispatcherServletrn rn contextConfigLocationrn classpath*:config/springAnnotation-servlet.xmlrn rn 1rn rn rn rn springMVCrn /rn rn [/code]rnrnspringAnnotation-servlet.xml代码如下:rn[code=html]rnrn rn rn rn rn rn rn rn rn rn rnrn rn rn rn rn [/code]rnrnUserController.java代码如下:rn[code=java]package com.controller.annotation;rnrnimport org.springframework.stereotype.Controller;rnimport org.springframework.web.bind.annotation.RequestMapping;rnimport org.springframework.web.bind.annotation.RequestMethod;rnimport org.springframework.web.servlet.ModelAndView;rnrn@Controllerrnpublic class UserController rn rn @RequestMapping(value="/user/addUser",method=RequestMethod.POST)rn public ModelAndView addUser()rn rn String result ="this is addUser------";rn return new ModelAndView("/annotation","result",result);rn rn rn @RequestMapping(value="/user/delUser",method=RequestMethod.GET)rn public ModelAndView delUser()rn String result ="this is delUser------";rn return new ModelAndView("/annotation","result",result);rn rn @RequestMapping(value="/user/toUser",method=RequestMethod.GET)rn public ModelAndView toUser()rn return new ModelAndView("/annotation");rn rnrn[/code]rnrnannotation.jsp代码如下:rn[code=html]<%@ page language="java" contentType="text/html; charset=UTF-8"rn pageEncoding="UTF-8"%>rn<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>rnrnrnrn rn rn Insert title herernrnrnrn rn springMVC注解1rn rn rn $result rn rn rn rnrn[/code]rn通过URL访问时总是提示警告: No mapping found for HTTP request with URI [/mvc4/user/addUser] in DispatcherServlet with name 'springMVC' 论坛

没有更多推荐了,返回首页