Spring Boot Security —— There is no PasswordEncoder mapped for the id “null”

Spring Boot Security —— 自帶login,登陸失敗《There is no PasswordEncoder mapped for the id “null”》

前言

代碼

  • 修改前代碼(出錯代碼)
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
	// 在內存中創建了一個用戶,該用戶的名稱爲user,密碼爲password,用戶角色爲USER
    auth.inMemoryAuthentication()
            .withUser("admin").password("admin").roles("USER");
    
}
  • 修改後代碼(問題解決)
@Autowired
public voidconfigureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    // 在內存中創建了一個用戶,該用戶的名稱爲user,密碼爲password,用戶角色爲USER
    auth.inMemoryAuthentication().passwordEncoder(new BCryptPasswordEncoder()).withUser("admin").password(new BCryptPasswordEncoder().encode("admin")).roles("USER");
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章