java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id “null”

Spring Boot2集成Security時候在頁面輸入用戶名密碼出現的異常,這是配置用戶的代碼

java.lang.IllegalArgumentException: There is no PasswordEncoder mapped
for the id “null”

/**
 * 描述:配置內存用戶
 * @param auth
 * @throws Exception
 */
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth
            .inMemoryAuthentication()
            .withUser("唐伯虎").password("123456").roles("ADMIN")
            .and()
            .withUser("秋香").password("123456").roles("USER");
}

解決:SpringBoot2集成Security的時候沒有加版本號,所以集成的Security 5版本的,它在設置密碼的時候需要增加如下代碼

下面代碼是不使用加密策略
如果使用加密策略可以配置Security的Bycrpt

@SuppressWarnings("deprecation")
@Bean
public static NoOpPasswordEncoder passwordEncoder() {
    return (NoOpPasswordEncoder) NoOpPasswordEncoder.getInstance();
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章