springBoot拦截器遇到的坑

在为App后台管理系统添加SpringBoot拦截器时遇到了问题。首次尝试导致重定向后的页面无法加载图片和CSS,尝试修改未果后暂时放弃。第二次尝试时出现无限重定向,经朋友建议将拦截路径改为/**解决,但原理不明。了解到/*和/**的区别,**会拦截任意层路径。个人疑惑为何登录页面能正常加载资源,期待解答。
摘要由CSDN通过智能技术生成

起因

  给app写了一个后台管理,最后想着加上拦截器吧省的客户不遵守游戏规则

拦截器代码

package com.example.app.comm;

import org.springframework.beans.factory.annotation.Value;
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 WebMvcConfig implements WebMvcConfigurer {

    @Value("${file.path}")
    private String path;
    public void  addResourceHandlers(ResourceHandlerRegistry registry){
        registry.addResourceHandler("/img/**").addResourceLocations("file:"+path);
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new L
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值