参考: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问题的更多相关文章

  1. spring boot 使用拦截器,注解 实现 权限过滤

    http://www.cnblogs.com/zhangXingSheng/p/7744997.html spring boot 使用拦截器 实现 用户登录拦截 http://www.cnblogs. ...

  2. Spring boot自定义拦截器和拦截器重定向配置简单介绍

    大家好: 本文简单介绍一下用于权限控制的Spring boot拦截器配置,拦截器重定向问题. 开发工具:jdk1.8   idea2017(付费版,网上找的破解教程) 1,首先使用idea创建一个Sp ...

  3. Spring Boot之拦截器与过滤器(完整版)

    作者:liuxiaopeng 链接:http://www.cnblogs.com/paddix 作者:蓝精灵lx原文:https://blog.csdn.net/liuxiao723846/artic ...

  4. Spring Boot整合拦截器

    过滤器和监听器都属于Servlet 的api,还可以使用 Spring 提供的拦截器(HandlerInterceptor)进行改更精细的控制.

  5. spring boot 添加拦截器

    构建一个spring boot项目. 添加拦截器需要添加一个configuration @Configuration @ComponentScan(basePackageClasses = Appli ...

  6. spring boot 添加拦截器的简单实例(springBoot 2.x版本,添加拦截器,静态资源不可访问解决方法)

    spring中拦截器主要分两种,一个是HandlerInterceptor,一个是MethodInterceptor 一.HandlerInterceptor HandlerInterceptor是s ...

  7. 【第四十章】Spring Boot 自定义拦截器

    1.首先编写拦截器代码 package com.sarnath.interceptor; import javax.servlet.http.HttpServletRequest; import ja ...

  8. Spring Boot (20) 拦截器

    动态资源和静态资源 拦截器可以算是aop的一种实现,专门拦截对动态资源的后台请求,也就是拦截对控制层的请求,主要用于判断用户是否有权限请求后台.拦截器不会拦截静态资源,如spring boot默认静态 ...

  9. spring boot使用拦截器

    1.编写一个拦截器 首先,我们先编写一个拦截器,和spring mvc方式一样.实现HandlerInterceptor类,代码如下 package com.example.demo.intercep ...

随机推荐

  1. 关于Server Tomcat v8.0 Server at localhost failed to start的解决办法

    测试环境: Eclipse Java EE IDE for Web Developers. Version: Luna Service Release 1 (4.4.1)Build id: 20140 ...

  2. 在谷歌浏览器中安装防广告的插件(abp)

    1.打开谷歌浏览器 2.打开 设置-->见到"扩展程序"--->在搜索框中搜索"adb"-->点击"Adblock plus&quo ...

  3. Atitit 图像处理 halcon类库的使用  范例边缘检测 attilax总结

    Atitit 图像处理 halcon类库的使用  范例边缘检测 attilax总结 1.1. 安装halcon11 ..体积大概1g压缩模式1 1.2. Halcon的科技树1 1.3. 启动 &qu ...

  4. socket.io笔记二之事件监听回调函数接收一个客户端的回调函数

    //服务端 socket.on('test', function (name, fn) { console.log(name) //输出yes fn('woot'); }); //客户端 socket ...

  5. 每日英语:Boost Your Balance; Avoid Falls

    If you find yourself needing to sit down to take off your shoes, it might be time to start paying at ...

  6. 每日英语:4G in China: A bigger deal than the iPhone

    Forget the breathless coverage of China Mobile offering the iPhone for a moment. Yes, it's huge news ...

  7. linux命令(51):set 指定行,直接替换并修改文件

    sed 命令: 指定行,从第一行到第一行: 把该行的ssd,换成cd: -i 表示的是替换并直接修改文件: sed  -i  '1,1s/ssd/cd/g' test_file 命令使用: sed - ...

  8. linux命令(46):批量更改文件后缀,文件名

    linux shell 1.要将所有 jpeg的后缀名图片文件修改为 jpg文件. rename .jpeg .jpg *.jpeg

  9. 李洪强和你一起学习前端之(9)规避脱标,CSS可见性,滑动门案例

    1  复习昨天知识 1.1 浮动  特点: >浮动的元素不占位置(脱标) >可以将行内元素转化为行内块元素 >块级元素在一行上显示 >设置了浮动的元素,影响其后面的元素   作 ...

  10. Lua语法基础(1)---简介、基本数据类型、表达式

    我觉得我已经陷入了一个坑内.因为,安装了Lua和SublimeText3编辑器之后,怎么使自己编写的lua代码在untiy内运行起来,是个我完全不了解的机制.先放一放吧.首先,来回顾一下Lua的语法基 ...