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


 

轉:

 

Did not find handler method for[/XXX.html]
苡菁 2018-03-29 10:18:02 6860 收藏
展開

  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才會找到這個對象
————————————————
版權聲明:本文為CSDN博主「苡菁」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/siyi1219/java/article/details/79738484


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM