一起学习网 一起学习网

springmvc 错误 Did not find handler method for

错误信息:RequestMappingHandlerMapping:330 - Did not find handler method for [/]

这错误很清楚知是扫描器没扫描到 @Controller 注解,仔细排查以下几点,特别是包名最好是复制粘贴,我就是犯了这个错误,包名手写错了,找了两天原因。

1、排查包名是否正确

2、扫描配置是否正确

3、注解扫描是否打开

<?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-3.2.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"
	default-lazy-init="true">

	
	
	错误写法<context:component-scan base-package="cn.qiping.controller" use-default-filters="false">
	正解写法<context:include-filter type="annotation" e­xpression="org.springframework.stereotype.Controller" />
	</context:component-scan>

	
	<mvc:annotation-driven />

	<!-- 定义跳转的文件的前后缀 ,视图模式配置-->
	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.UrlBasedViewResolver">
		<property name="viewClass"
			value="org.springframework.web.servlet.view.JstlView" />
		<property name="prefix" value="/WEB-INF/"/>
		<property name="suffix" value=".jsp" />
	</bean>

	<!-- 定义跳转的文件的前后缀 ,视图模式配置-->
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
         <property name="prefix" value="/WEB-INF/"></property>
         <property name="suffix" value=".jsp"></property>
    </bean>

    <mvc:default-servlet-handler />

	<!-- 配置文件上传 -->
	<bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="defaultEncoding" value="utf-8" />
        <property name="maxUploadSize" value="10485760000" />
        <property name="maxInMemorySize" value="40960" />
    </bean>

</beans>