zoukankan      html  css  js  c++  java
  • 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");
    }
  • 相关阅读:
    [Luogu P3626] [APIO2009] 会议中心
    杭电 1869 六度分离 (求每两个节点间的距离)
    杭电 1874 畅通工程续 (求某节点到某节点的最短路径)
    最短路径模板
    杭电 2544 最短路径
    POJ 1287 Networking (最小生成树模板题)
    NYOJ 1875 畅通工程再续 (无节点间距离求最小生成树)
    POJ 2485 Highways (求最小生成树中最大的边)
    杭电 1233 还是畅通工程 (最小生成树)
    杭电 1863 畅通工程 (最小生成树)
  • 原文地址:https://www.cnblogs.com/goloving/p/14880518.html
Copyright © 2011-2022 走看看