• o.s.web.servlet.PageNotFound : No mapping for GET /favicon.ico


    o.s.web.servlet.PageNotFound : No mapping for GET /favicon.ico

    遇到一个很奇怪的事情
    当前端调用接口的时候,所有逻辑功能都能正确完成,但是每次请求都会报这个错误
    反复检查了一下程序,我的controller里面根本就没有这个
    在这里插入图片描述

    翻了好多博客,需要加下面的配置

    • 使用WebMvcConfigurer接口时候,重写了参数解析器,而忽略了配置springMVC默认拦截静态资源
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
    import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
    
    @Configuration
    public class WebConfig implements WebMvcConfigurer {
    
        //解决  No mapping for GET /favicon.ico 访问静态资源图标
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            registry.addResourceHandler("/**")
                    .addResourceLocations("classpath:/static/");
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    翻看源码,@SpringbootApplicaton中以及有了@ComponentScan的注解
    重新再启动类添加 @ComponentScan(basePackages = {“com.demo.*”})的意义是什么???

    在这里插入图片描述

  • 相关阅读:
    深入linux内核架构--内存管理
    技术分享| gcc版本升级到5.2
    Java8新特性Stream流详解
    ARC121F Logical Operations on Tree
    16.linux应用实现控制led
    如何区分小角X射线散射和小角X射线衍射?
    24年计算机等级考试22个常见问题解答❗
    React之Hooks基础
    万能的python:实用小功能
    Blender-BlenderGIS插件
  • 原文地址:https://blog.csdn.net/weixin_43916074/article/details/126389285