HTTP Status 500 - There is no PasswordEncoder mapped for the id "null"

这篇博客介绍了在遇到HTTP Status 500错误,提示'No PasswordEncoder mapped for the id "null"'时,如何在Spring项目中排查并修复该问题。作者通过分享在UserServiceImpl.java中的代码修改过程,揭示了解决此类问题的关键步骤。
摘要由CSDN通过智能技术生成

报错情况如下:
在这里插入图片描述
UserServiceImpl.java 代码修改之前:

package com.cj.ssm.service.impl;

import com.cj.ssm.dao.IUserDao;
import com.cj.ssm.domain.UserInfo;
import com.cj.ssm.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service("userService")
@Transactional
public class UserServiceImpl implements IUserService {

	@Autowired
	private IUserDao userDao;

	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		UserInfo userInfo = null;
		try {
			userInfo = userDao.findByUsername(username);
		} catch (Exception e) {
			e.printStackTrace();
		}

		//处理自己的用户对象,封装成UserDetails
		User user = new User(userInfo.getUsername(),userInfo.getPassword(),getAuthority());
		return user;
	}

	//作用就是返回一个list集合,集合中装入的是角色描述
	public List<SimpleGrantedAuthority> getAuthority() {
		List<SimpleGrantedAuthority> list = new ArrayList<>();
		list.add(new SimpleGrantedAuthority("ROLE_USER"));
		return list;

	}
}

在这里插入图片描述
修改之后就正常了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值