寻找了一天的方法,都不能解决这个问题。
后来自己试了试不实用表单登录,发现可以了。
找到的几个解决办法:
https://www.zhangbj.com/p/524.html
https://www.baeldung.com/spring-boot-security-autoconfiguration
表单登录时 loginPage方法的原理:
https://stackoverflow.com/questions/28658265/how-to-remove-a-filter-from-spring-security
(这就是为什么当自定义页面后,不会出现spring security自带的页面)
可以去看看这个类,了解原理:
public abstract class AbstractAuthenticationFilterConfigurer<B extends HttpSecurityBuilder<B>,T extends AbstractAuthenticationFilterConfigurer<B,T, F>, F extends AbstractAuthenticationProcessingFilter> extends AbstractHttpConfigurer<B>
我的解决办法:
// securityhttp.and()
// .formLogin(); // Use form login
删掉了表单登录。
其实在spring boot 项目启动时,控制台可以看到当前FilterChain的顺序。
里面有三个filter:
org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter
org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter
有这三个filter就会出现自带的登录页面。