• 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())
    
  • 相关阅读:
    vue-常用指令汇总
    vue-插槽和具名插槽
    vue-传值校验
    vue-动态组件
    vue-组件
    zend studio 快捷键收集
    php调试工具firephp
    zend studio插件
    MySQL各个版本区别
    PHP 中 Date 函数与实际时间相差8小时的解决方法
  • 原文地址:https://www.cnblogs.com/hfultrastrong/p/8857185.html
Copyright © 2020-2023  润新知