一、报错: java.lang.IllegalStateException: Can‘t configure antMatchers after anyRequest
启动springboot项目,直接编译报错,内容:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.NullPointerException
下面还有报错:
nested exception is java.lang.IllegalStateException: Can‘t configure antMatchers after anyRequest
解决方案:
二、认证密码没加密,报错:java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null"
认证密码需要加密才行,如果没有使用下面的密码加密,就会报上面错误
// 认证的密码得加密才行
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().passwordEncoder(new BCryptPasswordEncoder())
.withUser("gwf").password(new BCryptPasswordEncoder().encode("123456")).roles("vip1");
}