spring boot 使用拦截器 无法注入 配置值 、bean问题
参考:https://www.cnblogs.com/SimonHu1993/p/8360701.html
一定要将 拦截器组件 交给spring容器进行管理,这样才能注入配置值,或者注入bean:
package com.thunisoft.maybeemanagementcenter.interceptor; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; @Configuration
public class WebAppConfigure extends WebMvcConfigurerAdapter { @Value("${thunisoft.microservice.mvc.interceptor.includePath:/**}")
private String includePath;
@Value("${thunisoft.microservice.mvc.interceptor.excludePath:/login/*}")
private String excludePath; @Override
public void addInterceptors(InterceptorRegistry registry) {
String[] excludePaths = excludePath.split(",");
String[] includePaths = includePath.split(",");
InterceptorRegistration ir = registry.addInterceptor(loginInterceptor())
.addPathPatterns(includePaths)
.excludePathPatterns(excludePaths);
super.addInterceptors(registry);
} @Bean
public LoginInterceptor loginInterceptor() {
return new LoginInterceptor();
}
}
重点代码:
@Bean
public LoginInterceptor loginInterceptor() {
return new LoginInterceptor();
}
registry.addInterceptor(loginInterceptor())
spring boot 使用拦截器 无法注入 配置值 、bean问题的更多相关文章
- spring boot 使用拦截器,注解 实现 权限过滤
http://www.cnblogs.com/zhangXingSheng/p/7744997.html spring boot 使用拦截器 实现 用户登录拦截 http://www.cnblogs. ...
- Spring boot自定义拦截器和拦截器重定向配置简单介绍
大家好: 本文简单介绍一下用于权限控制的Spring boot拦截器配置,拦截器重定向问题. 开发工具:jdk1.8 idea2017(付费版,网上找的破解教程) 1,首先使用idea创建一个Sp ...
- Spring Boot之拦截器与过滤器(完整版)
作者:liuxiaopeng 链接:http://www.cnblogs.com/paddix 作者:蓝精灵lx原文:https://blog.csdn.net/liuxiao723846/artic ...
- Spring Boot整合拦截器
过滤器和监听器都属于Servlet 的api,还可以使用 Spring 提供的拦截器(HandlerInterceptor)进行改更精细的控制.
- spring boot 添加拦截器
构建一个spring boot项目. 添加拦截器需要添加一个configuration @Configuration @ComponentScan(basePackageClasses = Appli ...
- spring boot 添加拦截器的简单实例(springBoot 2.x版本,添加拦截器,静态资源不可访问解决方法)
spring中拦截器主要分两种,一个是HandlerInterceptor,一个是MethodInterceptor 一.HandlerInterceptor HandlerInterceptor是s ...
- 【第四十章】Spring Boot 自定义拦截器
1.首先编写拦截器代码 package com.sarnath.interceptor; import javax.servlet.http.HttpServletRequest; import ja ...
- Spring Boot (20) 拦截器
动态资源和静态资源 拦截器可以算是aop的一种实现,专门拦截对动态资源的后台请求,也就是拦截对控制层的请求,主要用于判断用户是否有权限请求后台.拦截器不会拦截静态资源,如spring boot默认静态 ...
- spring boot使用拦截器
1.编写一个拦截器 首先,我们先编写一个拦截器,和spring mvc方式一样.实现HandlerInterceptor类,代码如下 package com.example.demo.intercep ...
随机推荐
- [MeetCoder] Crossing Bridge
Crossing Bridge Description N people wish to cross a bridge at night. It’s so dark around there that ...
- 4-4-串的KMP匹配算法-串-第4章-《数据结构》课本源码-严蔚敏吴伟民版
课本源码部分 第4章 串 - KMP匹配算法 ——<数据结构>-严蔚敏.吴伟民版 源码使用说明 链接☛☛☛ <数据结构-C语言版>(严蔚敏,吴伟民版)课本源码 ...
- 每日英语:How Your Knees Can Predict the Weather
The Wolff family of Paramus, N.J., was eyeing the gathering clouds and debating whether to cancel a ...
- HBase最佳实践-用好你的操作系统
终于又切回HBase模式了,之前一段时间因为工作的原因了解接触了一段时间大数据生态的很多其他组件(诸如Parquet.Carbondata.Hive.SparkSQL.TPC-DS/TPC-H等),虽 ...
- LeetCode: Search a 2D Matrix 解题报告
Search a 2D Matrix Write an efficient algorithm that searches for a value in an m x n matrix. This m ...
- python 字符串编码 str和unicode 区别以及相互转化 decode('utf-8') encode('utf-8')
- IOS 禁止侧滑返回上个页面功能
1.首先把顶部左侧返回按钮隐藏掉 //隐藏返回按钮 self.navigationItem.hidesBackButton = YES; 2.1.再禁止页面左侧侧 //禁止页面左侧滑动返回,注意,如果 ...
- app测试初窥
要用到的两个神器:abd&drozer adb介绍 adb的全称为Android Debug Bridge,就是起到调试桥的作用,作为一名开发者倒是常用到这个工具.借助adb工具,我们可以管理 ...
- [转]获取JAVA[WEB]项目相关路径的几种方法
http://blog.csdn.net/yaerfeng/article/details/7297479/ 在jsp和class文件中调用的相对路径不同. 在jsp里,根目录是WebRoot 在cl ...
- Python进阶(三十五)-Fiddler命令行和HTTP断点调试
Python进阶(三十五)-Fiddler命令行和HTTP断点调试 一. Fiddler内置命令 上一节(使用Fiddler进行抓包分析)中,介绍到,在web session(与我们通常所说的se ...