org.springframework.web.servlet.DispatcherServlet.noHandlerFound No mapping for GET /****/**错误解析

上来先

两句

卧槽!卧槽!卧槽!

找了俩小时,我哭了

主要检查SpringMVC配置文件

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

    <!--只扫描controller里面的文件-->
    <context:component-scan base-package="com.galaxy">
        <!--exclude:排除-->
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
       

    <!--配置视图解析器-->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>

<!--
    &lt;!&ndash;过滤静态资源&ndash;&gt;
    <mvc:resources mapping="/css/**" location="/css/"/>
    <mvc:resources mapping="/img/**" location="/img/"/>
    <mvc:resources mapping="/js/**" location="/js/"/>
-->

    <!--配置SpringMVC注解扫描-->
    <mvc:annotation-driven/>
</beans>

运行后,路径正确,显示不出来内容
在这里插入图片描述

这个是我遇到的一个错误,大概的意思就是没有映射

13-Apr-2020 22:56:31.841 警告 [http-nio-8081-exec-18] org.springframework.web.servlet.DispatcherServlet.noHandlerFound No mapping for GET /queryAll1

因为我用的是IDEA工具,
有自动生成的代码,没有仔细看。
还有自己的基础差,不理解。
最后终于找到了。

这个是修改后的SpringMVC文件

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

    <!--只扫描controller里面的文件-->
    <context:component-scan base-package="com.galaxy">
        <!--exclude:排除-->
       <!-- <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>-->
        <!--include 包括-->
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

    <!--配置视图解析器-->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>

<!--
    &lt;!&ndash;过滤静态资源&ndash;&gt;
    <mvc:resources mapping="/css/**" location="/css/"/>
    <mvc:resources mapping="/img/**" location="/img/"/>
    <mvc:resources mapping="/js/**" location="/js/"/>
-->

    <!--配置SpringMVC注解扫描-->
    <mvc:annotation-driven/>
</beans>

我把< context:include-filter > include:包括 写成 < context:exclude-filter > exclude:排除

完全写反了,能出来才见鬼了。
修改之后页面就显示出来了
在这里插入图片描述

希望能够辅助你解决问题!

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值