• 首页
  • 邻居
  • 关于
  • 归档
  • 搜索
  • 夜间模式
    ©2020-2026  我的学习笔记 Theme by OneBlog

    我的学习笔记博客

    搜索
    标签
    # 随笔 # Java # 教程 # openwrt # Mysql # SQL # 爬虫 # post # Js调优 # MAVEN
  • 首页>
  • 教程>
  • 正文
  • springboot拦截器放行静态资源

    2020年05月14日 4.7 k 阅读 7 评论 1358 字

    springboot拦截器放行静态资源
    # 编写一个类
    实现 WebMvcConfigurer

    ```java
    package com.my.blog.website.interceptor;
    import com.my.blog.website.utils.TaleUtils;
    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;

    import javax.annotation.Resource;

    /**
    * 向mvc中添加自定义组件
    * Created by BlueT on 2017/3/9.
    * 更换MVC配置类
    */
    @Configuration
    public class WebMvcConfig implements WebMvcConfigurer {
    @Resource
    private BaseInterceptor baseInterceptor;
    @Resource
    private IpInterceptor ipInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(ipInterceptor);
    registry.addInterceptor(baseInterceptor);
    }

    /**
    * 添加静态资源文件,外部可以直接访问地址
    *
    * @param registry
    */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    registry.addResourceHandler("/upload/**").addResourceLocations("file:" + TaleUtils.getUplodFilePath() + "upload/");
    }
    }

    ```

    本文著作权归作者 [ admin ] 享有,未经作者书面授权,禁止转载,封面图片来源于 [ 互联网 ] ,本文仅供个人学习、研究和欣赏使用。如有异议,请联系博主及时处理。
    教程
    取消回复

    发表留言
    回复

    读者留言7

    1. 李白 Lv.1
      2021-04-01 16:25 回复

      qgtwhetynetynne

    2. 路人甲 Lv.1
      2020-08-18 11:19 回复

      :meigui::meigui::meigui::shenli::shenli::yinxian::yinxian::yinxian::yinxian::damuzhi::damuzhi::damuzhi::damuzhi::haha2:

    3. adfa Lv.1
      2020-05-14 14:19 回复

      :hu::han::caihong::caihong::caihong::caihong::caihong::caihong::caihong::caihong::caihong::caihong::caihong::caihong::yinxian::weiqu:

    4. adfa Lv.1
      2020-05-14 14:15 回复

      :mianqiang::mianqiang::taikaixin::neng::huaxin::yi::tu:

    加载更多评论
    加载中...
    — 已加载全部评论 —
    首页邻居关于归档
    Copyright©2020-2026  All Rights Reserved.  Load:0.020 s
    京ICP备18019712号
    Theme by OneBlog V3.6.5
    夜间模式

    开源不易,请尊重作者版权,保留基本的版权信息。