Did not find handler method for[/XXX.html]

  console: 日志为

2016-04-08 15:21:47 Looking up handler method for path /welcome
2016-04-08 15:21:47 Did not find handler method for [/welcome]
2016-04-08 15:21:47 No mapping found for HTTP request with URI [/springMVC/welcome] in DispatcherServlet with name 'spring'

2016-04-08 15:21:47 Successfully completed request

解决方法:

解决1:

<mvc:annotation-driven/>
       <context:component-scan base-package="com.mvc.rest/*"></context:component-scan>

  改为

<mvc:annotation-driven/>
       <context:component-scan base-package="com.mvc.rest"></context:component-scan>

  去掉/*

解决2: 

        或者改为

        <mvc:annotation-driven/>

       <context:component-scan base-package="com.mvc.*"></context:component-scan>

    

    原因component-scan base-package配置的是路径名称

           如  value='com.mvc.rest'  则 扫描这个包路径下的java bean, 如果配置的 com.mvc.*  则扫描com.mvc包下的子包, 如果是com.mvc.rest.*则扫描com.mvc.rest

下所有的子包,因为com.mvc.rest没有子包,所以此处显示“Did not find handler method for”日志

如果以上方法没有解决问题,可以尝试如下:

springmvc.xml文件是这样的

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


    <mvc:annotation-driven />
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/jsps/user/"/>
        <property name="suffix" value=".jsp"/>
    </bean>
</beans>

spring.xml文件中内容这样写的

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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/aop 
    http://www.springframework.org/schema/aop/spring-aop-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/util 
    http://www.springframework.org/schema/util/spring-util-4.0.xsd">
    <context:component-scan base-package="com.hs"/>
    <!-- 加载属性配置文件 -->
    <context:property-placeholder location="classpath:db.properties"/>
    <!-- 配置数据源 -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="${jdbc.driverClass}"/>
        <property name="url" value="${jdbc.jdbcUrl}"/>
        <property name="username" value="${jdbc.user}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>
    <!-- 配置sqlsessionfactory --> 
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml"/>
    </bean>

    <!-- 事务管理 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <!-- 配置通知 -->
    <tx:advice id="txAdvicer" transaction-manager="transactionManager">
        <tx:attributes>
        <tx:method name="find*" propagation="REQUIRED"/>
        <tx:method name="get*" propagation="REQUIRED"/>
        <tx:method name="save*" propagation="REQUIRED"/>
        <tx:method name="update*" propagation="REQUIRED"/>
        <tx:method name="insert*" propagation="REQUIRED"/>
        <tx:method name="delete*" propagation="REQUIRED"/>
        <tx:method name="*" propagation="REQUIRED"/>
        </tx:attributes>
    </tx:advice>
    <aop:config>
        <aop:advisor advice-ref="txAdvicer" pointcut="execution(* com.hs.service.*.*(..))"/>
    </aop:config>
    <!-- 打开全局注解扫描qi -->

    <!-- 批量配置mapper接口dao -->
    <bean  class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.hs.dao"/>
    <!--    <property name="sqlSessionFactory" ref="sqlSessionFactory"/> -->
    </bean>


</beans>

其实就是一个扫描的配置写错了位置

<context:component-scan base-package="com.hs"/>

这行配置时必须要写在springmvc.xml文件中,因为加载该文件时,会扫描所有的加注解的controller,这样RequestMappingHandlerMapping才会找到这个对象





猜你喜欢

转载自blog.csdn.net/siyi1219/article/details/79738484