zoukankan      html  css  js  c++  java
  • 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())
    
  • 相关阅读:
    如何让 PADS Layout 识别到板框
    笔记:理想和挣钱
    笔记:知数据不知情况
    关于ie6下拖动滚动条时,div抖动的问题解决
    jQuery 中屏蔽浏览器的F5刷新功能
    jQuery 的append在ie下的兼容性
    协程
    进程
    操作系统的发展史
    python_控制台输出带颜色的文字方法
  • 原文地址:https://www.cnblogs.com/hfultrastrong/p/8857185.html
Copyright © 2011-2022 走看看