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 ...
随机推荐
- ElasticSearch 数据增删改实现
前言 本文介绍 ElasticSearch 增加.删除.修改数据的使用示例.通过Restful 接口和 Python 实现.ES最新版本中有Delete By Query 和 Update By Qu ...
- SQL SERVER 查看数据库信息
a.使用sys.database_files查看有关数据库文件的信息 b.使用sys.filegroups查看有关数据库组的信息. c.使用sys.master_files 查看数据库文件的基本信息和 ...
- 【Android开发】Api_Android_Distribute
原文链接:http://android.eoe.cn/topic/android_sdk {"version": "20120817","pageid ...
- bestcoder 48# wyh2000 and a string problem (水题)
wyh2000 and a string problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K ...
- 【Unity】9.3 粒子系统生成器详解
分类:Unity.C#.VS2015 创建日期:2016-05-02 一.简介 上一节已经介绍过了在Unity 5.x中两种创建粒子效果的方式(方式1.方式2). 这一节我们主要学习第2种方式的基本概 ...
- mac 上面安装jdk 1.6
下载地址 https://support.apple.com/kb/dl1572?locale=zh_CN orcale 支持mac的最低版本是1.7
- Android Lock Pattern 图案解锁
参考链接:http://www.cnblogs.com/dyingbleed/archive/2012/12/03/2800007.html http://blog.csdn.net/way_ping ...
- NET二进制图片存储与读取的常见方法,iTextSharp添加图片生成PDF文件
public void iTextSharpCreatPDF() { string pdfpath = System.Web.HttpContext.Current.Server.MapPath(&q ...
- Vmware虚拟硬盘合并多个分割文件
有时,当我们创建虚拟机vmware里面的应用程序,我们可能会选择创建分割的虚拟磁盘中的多个文件2 GB的文件,这是为了提高复制过程,主要用于存储虚拟机文件系统不支持创建更大的文件. 如果我们需要将它转 ...
- [Windows Azure] How to Monitor Cloud Services
How to Monitor Cloud Services To use this feature and other new Windows Azure capabilities, sign up ...