zoukankan      html  css  js  c++  java
  • springboot2.0 使用拦截器后,导致静态文件访问不到的解决方案

     1 package com.leenleda.ward.tv.admin.interceptor;
     2 
     3 import com.leenleda.ward.tv.common.config.LeenledaConfig;
     4 import org.springframework.beans.factory.annotation.Autowired;
     5 import org.springframework.context.annotation.Configuration;
     6 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
     7 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
     8 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
     9 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
    10 
    11 import javax.annotation.Resource;
    12 import java.util.Arrays;
    13 
    14 
    15 /**
    16  * @Author: pengbenlei
    17  * @Date: 2020/2/19 11:22
    18  * @Description:
    19  */
    20 @Configuration
    21 @EnableWebMvc
    22 public class CustomMVCConfiguration implements WebMvcConfigurer {
    23 
    24     @Resource
    25     LoginInterceptor loginInterceptor;
    26 
    27     @Autowired
    28     LeenledaConfig leenledaConfig;
    29     @Override
    30     public void addInterceptors(InterceptorRegistry registry) {
    31         //登录拦截器
    32         registry.addInterceptor(loginInterceptor).addPathPatterns("/admin/**")
    33                 .excludePathPatterns(Arrays.asList("/file/**"));
    34     }
    35 
    36     /**
    37      * 添加静态资源文件,外部可以直接访问地址
    38      * @param registry
    39      */
    40     @Override
    41     public void addResourceHandlers(ResourceHandlerRegistry registry) {
    42         String locationPath="file:"+leenledaConfig.getLeenledaUploadRoot()+"/leenleda/application/";
    43         registry.addResourceHandler("/file/**")
    44                 .addResourceLocations(locationPath);
    45     }
    46 
    47 }
    拦截器注册

    其中file是自定义的虚拟路径,访问时过滤掉拦截,addResourceLocations 要访问的文件路径。

    参考地址  https://www.jianshu.com/p/6469e9c37605

  • 相关阅读:
    存储过程语法二
    存储过程语法一
    存储过程的优点
    .NET中Redis安装部署及使用方法简介
    UEditor富文本web编辑器
    未找到与约束contractname Microsoft.VisualStudio.Utilities.IContentTypeRegistryService
    comet 推送消息到客户端
    文本框 只能输入数字和小数点验证
    asp.net Cache
    Windows10放开Administrator权限
  • 原文地址:https://www.cnblogs.com/rolayblog/p/12619932.html
Copyright © 2011-2022 走看看