SpringBoot 自定义 Filter 不生效的原因之一:未注册过滤器

yufei       1 年, 6 月 前       3243

SpringBoot 自定义 Filter 不生效的原因之一就是未注册过滤器,需要在 Application 上添加下面的注解

@ServletComponentScan(basePackages = "cn.twle.java.demo.demo.filters")

例如

package cn.twle.java.demo.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@ComponentScan("cn.twle.java.demo.demo")
@SpringBootApplication(exclude = {
        org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class
})

@ServletComponentScan(basePackages = "cn.twle.java.demo.demo.filters")
public class DemoApplication {

    public static void main(String[] args) {

        SpringApplication.run(DemoApplication.class, args);
    }
}
目前尚无回复
简单教程 = 简单教程,简单编程
简单教程 是一个关于技术和学习的地方
现在注册
已注册用户请 登入
关于   |   FAQ   |   我们的愿景   |   广告投放   |  博客

  简单教程,简单编程 - IT 入门首选站

Copyright © 2013-2022 简单教程 twle.cn All Rights Reserved.