import lombok.extern.slf4j.Slf4j;
import org.manage.management.permission.interceptor.LoginInterceptor;
import org.manage.management.permission.interceptor.RightsInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*; import javax.servlet.MultipartConfigElement; @Slf4j
@Configuration //使用注解 实现拦截
public class WebAppConfigurer implements WebMvcConfigurer { @Autowired
RightsInterceptor rightsInterceptor; @Autowired
LoginInterceptor loginInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
//登录拦截的管理器
//拦截的对象会进入这个类中进行判断
InterceptorRegistration registration = registry.addInterceptor(loginInterceptor);
//所有路径都被拦截
registration.addPathPatterns("/**");
//添加不拦截路径
registration.excludePathPatterns("/","/m/**","/mm/**","/login","/admin/login","/error","/static/**","/logout","/images/**"
); // 权限拦截的管理器
InterceptorRegistration registration1 = registry.addInterceptor(rightsInterceptor);
//所有路径都被拦截
registration1.addPathPatterns("/**");
//添加不拦截路径
registration1.excludePathPatterns("/","/m/**","/mm/**","/login","/admin/login","/error","/static/**","/logout","/images/**");
} @Value("${imagesPath}")
private String mImagesPath; /**
* 将指定路径的文件 ,映射成网站某路径下的文件
* 例如将 /images/4.jpg 对应到 file:E://桌面/Shop/management/upload/file/images/4.jpg
* **/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
if(mImagesPath.equals("") || mImagesPath.equals("${imagesPath}")){
String imagesPath = WebAppConfigurer.class.getClassLoader().getResource("").getPath();
if(imagesPath.indexOf(".jar")>0){
imagesPath = imagesPath.substring(0, imagesPath.indexOf(".jar"));
}else if(imagesPath.indexOf("classes")>0){
imagesPath = "file:"+imagesPath.substring(0, imagesPath.indexOf("classes"));
}
imagesPath = imagesPath.substring(0, imagesPath.lastIndexOf("/"))+"/images/";
mImagesPath = imagesPath;
} System.out.println("本地路径:" + mImagesPath + "。。已经映射到路由/m/**之下");
registry.addResourceHandler("/m/**").addResourceLocations(mImagesPath);
registry.addResourceHandler("/mm/**").addResourceLocations(mImagesPath);
} }

个人完善的springboot拦截器的更多相关文章

  1. Java结合SpringBoot拦截器实现简单的登录认证模块

    Java结合SpringBoot拦截器实现简单的登录认证模块 之前在做项目时需要实现一个简单的登录认证的功能,就寻思着使用Spring Boot的拦截器来实现,在此记录一下我的整个实现过程,源码见文章 ...

  2. SpringBoot拦截器中Bean无法注入(转)

    问题 这两天遇到SpringBoot拦截器中Bean无法注入问题.下面介绍我的思考过程和解决过程: 1.由于其他bean在service,controller层注入一点问题也没有,开始根本没意识到Be ...

  3. 【SpringBoot】SpringBoot拦截器实战和 Servlet3.0自定义Filter、Listener

    =================6.SpringBoot拦截器实战和 Servlet3.0自定义Filter.Listener ============ 1.深入SpringBoot2.x过滤器Fi ...

  4. SpringBoot拦截器中无法注入bean的解决方法

    SpringBoot拦截器中无法注入bean的解决方法 在使用springboot的拦截器时,有时候希望在拦截器中注入bean方便使用 但是如果直接注入会发现无法注入而报空指针异常 解决方法: 在注册 ...

  5. Springboot拦截器未起作用

    之前遇到要使用springboot拦截器却始终未生效的状况,查了网上的博客,大抵都是@Component,@Configuration注解未加,或是使用@ComponentScan增加包扫描,但是尝试 ...

  6. SpringBoot拦截器中service或者redis注入为空的问题

    原文:https://my.oschina.net/u/1790105/blog/1490098 这两天遇到SpringBoot拦截器中Bean无法注入问题.下面介绍我的思考过程和解决过程: 1.由于 ...

  7. springboot + 拦截器 + 注解 实现自定义权限验证

    springboot + 拦截器 + 注解 实现自定义权限验证最近用到一种前端模板技术:jtwig,在权限控制上没有用springSecurity.因此用拦截器和注解结合实现了权限控制. 1.1 定义 ...

  8. Springboot 拦截器配置(登录拦截)

    Springboot 拦截器配置(登录拦截) 注意这里环境为springboot为2.1版本 1.编写拦截器实现类,实现接口   HandlerInterceptor, 重写里面需要的三个比较常用的方 ...

  9. Springboot拦截器实现IP黑名单

    Springboot拦截器实现IP黑名单 一·业务场景和需要实现的功能 以redis作为IP存储地址实现. 业务场景:针对秒杀活动或者常规电商业务场景等,防止恶意脚本不停的刷接口. 实现功能:写一个拦 ...

随机推荐

  1. engine_init_options.go

    package ) type {         options.PersistentStorageShards = defaultPersistentStorageShards     } }

  2. public_handers.go

    package],,) ],,) ]:],,);:],],,) ) ]],,) )) ,) ))         if etagMatch {             w.WriteHeader(ht ...

  3. version.go

    package blog4go const ( // 版本号 VERSION = "0.5.6" )

  4. tomcat设置直接通过域名访问项目(不需要接 /项目名)

    本文转自 : https://blog.csdn.net/qq_33647275/article/details/52585489 效果图 打开 tomcat - ->conf- ->se ...

  5. YAML基础教程

    一.YAML介绍YAML参考了其他多种语言,包括:XML.C语言.Python.Perl以及电子邮件格式RFC2822.Clark Evans在2001年5月在首次发表了这种语言,另外Ingy döt ...

  6. OKHttp源码学习同步请求和异步请求(二)

    OKHttp get private void doGet(String method, String s) throws IOException { String url = urlAddress ...

  7. c#Socket服务器与客户端的开发(1)

    上个项目中用到了Socket通讯,项目中直接借助SuperSocket实现,但是我觉得这毕竟是一个我没接触过的东西,所以也顺便学习了一下原生socket的使用,做了一个socket服务器与客户端的开发 ...

  8. Scala 编码习惯

    1. 不用var.var是可以被不断修改的,而val是不能被修改的.使用val而不是var能让你的程序更强壮,bug更少,更好调试,更容易测试,在并发条件下,更容易调优而获得更好的性能.数学证明我们不 ...

  9. Asp.Net Core 轻松学-多线程之取消令牌

    前言     取消令牌(CancellationToken) 是 .Net Core 中的一项重要功能,正确并合理的使用 CancellationToken 可以让业务达到简化代码.提升服务性能的效果 ...

  10. ASP.NET Razor

    一.为什么要学习Razor? 可以让服务器代码(就是c#和vb)嵌入到网页中,也就是说这个页面中包含html代码和C#(vb)代码.基于服务器的代码可以在网页传送给浏览器时,创建动态 Web 内容.当 ...