关于SSM注解开发中,UserServiceImpl的注入问题错误排查
作者:互联网
Error creating bean with name ‘userServiceImpl’: Unsatisfied dependency expressed through field ‘userMapper’;
项目架构
排查问题一:@Service,@Autowired没注入
UserServiceImpl
package com.song.travel.service.impl;
import com.song.travel.mapper.UserMapper;
import com.song.travel.pojo.User;
import com.song.travel.pojo.UserExample;
import com.song.travel.req.UserVo;
import com.song.travel.service.UserService;
import com.song.travel.utils.BeanConv;
import com.song.travel.utils.EmptyUtil;
import com.song.travel.utils.MD5Coder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpSession;
import java.util.List;
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Autowired
HttpSession session;
/**
* 用户注册:
* 将请求携带的用户数据保存到数据库中
* @param userVo
* @return
*/
@Override
public Boolean registerUser(UserVo userVo) {
// 将vo对象转成pojo对象
// User user1 = BeanConv.toBean(userVo, new User());
User user = BeanConv.toBean(userVo, User.class);
// 对密码进行加密
String md5Password = MD5Coder.md5Encode(user.getPassword());
user.setPassword(md5Password);
// dao层需要的pojo对象
int i = userMapper.insertSelective(user);
return i>0;
}
/**
* 用户登录:
* 根据用户名和密码查询用户表,查询到则登录成功
* 查询不到则登录失败
* @param userVo
* @return
*/
@Override
public UserVo loginUser(UserVo userVo) {
// 存放查询条件
UserExample example = new UserExample();
example.createCriteria()
.andUsernameEqualTo(userVo.getUsername())
.andPasswordEqualTo(MD5Coder.md5Encode(userVo.getPassword()));
List<User> users = userMapper.selectByExample(example);
UserVo userVoResult = new UserVo();
if(users.size()>0){
// 获取查询结果数据
User user = users.get(0);
// 对象转换
BeanConv.toBean(user, userVoResult);
// 登录成功后,保存登录成功的状态(将登录成功的用户信息保存到Session中)
String id = session.getId();
// 将存放用户对象的唯一标记(key),交个当前对象
userVoResult.setSessionId(id);
session.setAttribute(id,userVoResult);
}
return userVoResult;
}
/**
* 退出操作
* 将session中对应的对象删除
*/
@Override
public void loginOutUser() {
//session.invalidate();
String id = session.getId();
session.removeAttribute(id);
}
/**
* 判断用户是否登录
* @return
*/
@Override
public Boolean isLogin() {
// 从session中获取登录的用户信息
Object userVo = session.getAttribute(session.getId());
// 如果对象为空返回true,不为空返回false
boolean flag = EmptyUtil.isNullOrEmpty(userVo);
return !flag;
}
}
问题二:dao层Mapper 未注入
问题三:扫包问题
问题四:SSM配置中Configuration未放入,需要加载入Spring
标签:UserServiceImpl,userVo,song,travel,SSM,session,import,注解,com 来源: https://blog.csdn.net/weixin_43390142/article/details/112910696