Spring Security 报There is no PasswordEncoder mapped for the id "null"
2024-09-05 18:53:45
查了下发现是spring security 版本在5.0后就要加个PasswordEncoder了
解决办法
- 在securityConfig类下加入NoOpPasswordEncoder,不过官方已经不推荐了
@Bean
public static NoOpPasswordEncoder passwordEncoder() {
return (NoOpPasswordEncoder) NoOpPasswordEncoder.getInstance();
}
- 在securityConfig类下加入密码加密,在数据库中存的密码也是要经过这个加密的才能匹配上
@Autowired
private UserDetailsService customUserService;
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(customUserService).passwordEncoder(new BCryptPasswordEncoder());
}
补充:加密操作
public static void main(String[] args) {
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
//加密"0"
String encode = bCryptPasswordEncoder.encode("0");
System.out.println(encode);
//结果:$2a$10$/eEV4X7hXPzYGzOLXfCizu6h7iRisp7I116wPA3P9uRcHAKJyY4TK
}
作者:yyq唯心不易
链接:https://www.jianshu.com/p/9e7792d767b2
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
最新文章
- nw.js桌面软件开发系列 第0.1节 HTML5和桌面软件开发的碰撞
- HTML5初学总结
- JIRA 6.3.6版本部署
- ionic添加admob广告教程
- LTMP手动编译安装以及全自动化部署实践(附详细代码)
- Java WEB —— Java提升
- 如何在 Windows Azure 的虚拟机 ubuntu 上面安装和配置 openVPN(二)
- C#解leetcode 106. Construct Binary Tree from Inorder and Postorder Traversal
- 逆向并查集 hrbust 1913
- Operation System - Peterson&;#39;s Solution算法 解决多线程冲突
- Ubuntu 12.04 下安装git
- Phaser小游戏
- Itunes制作手机铃声,图文版
- 常用Oracle进程资源查询语句(运维必看)
- GCD API记录(二)
- Linux中shell和子shell一点点理解
- hadoop fsck详解
- MetaMask/sw-controller
- A pointer is a variable whose value is the address of another variable 指针 null pointer 空指针 内存地址0 空指针检验
- CentOS7安装部署zabbix3.4操作记录
热门文章
- centos7配置mysql8.0主从复制
- vue.js 分页加载,向上滑动,依次加载数据。
- Shiro多Realm验证
- pycharm 激激活码
- aria2的安装与配置
- Kubernetes集群详细介绍及部署
- [BZOJ1299]巧克力棒(博弈论,线性基)
- Codeforces 919 行+列前缀和 树上记忆化搜索(树形DP)
- 如果该虚拟机未在使用,请按“获取所有权(T)”按钮获取它的所有权。否则,请按“取消(C)”按钮以防损坏
- C++打开属性对话框并保持其处于打开状态