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路径 。

猜你喜欢

转载自new-mao-er.iteye.com/blog/2236535
今日推荐