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); } }
目前尚无回复