• SpringSecurity常见报错处理:Can't configure antMatchers after anyRequest、There is no PasswordEncoder mapped for the id "null"


    一、报错: 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

      解决方案:

      开始配了半天,一直报这个:Can't configure antMatchers after anyRequest...的错误,上StackOverflow看了以下别人的,照着代码调整了下还是没有解决。然后想难道是super.configure(http)里搞的鬼,点进去看了下,结果还真是,就赶紧去掉了。

      子类重写方法时, 如果用不到父类的方法, 一定要去掉自动生成的super。

    二、认证密码没加密,报错: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");
    }
  • 相关阅读:
    【ci框架】ci框架目录结构分析
    php CI框架
    jQuery boxy弹出层插件中文演示及讲解
    Jenkins构建报错(Jenkins is reserved for jobs with matching label expression)解决办法
    redis缓存数据架构实战
    Git免密码pull&push
    Maven搭建Nexus私有仓库
    Windows使用filezilla搭建FTP服务器
    CentOS7.4使用yum安装MySQL5.6
    MySQL数据库连接池导致页面登录无法查询问题解决过程
  • 原文地址:https://www.cnblogs.com/goloving/p/14880518.html
Copyright © 2020-2023  润新知