• 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.*”})的意义是什么???

    在这里插入图片描述

  • 相关阅读:
    Activity数据库字段说明
    指令FTP/SFTP(有/无密码)连接、下载以及上传
    若依和芋道
    python——线程总结
    【多线程案例】设计模式-单例模式
    【力扣题解】1413. 逐步求和得到正数的最小值【每日一题】
    FreeRTOS移植
    你必须知道的4种 Redis 集群方案及优缺点对比
    韩国市场最全开发攻略
    rust数组
  • 原文地址:https://blog.csdn.net/weixin_43916074/article/details/126389285