整合SSM遇到这个问题,大佬们进来看看吧

开源之夏第三届火热来袭,高校学生参与赢万元奖金!>>>

整合SSM遇到这个问题,大佬们进来看看吧

报错:org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'playersServiceImpl': Unsatisfied dependency expressed through method 'setPlayersMapper' parameter 0;

解决方案:

1,先看看Service层类上的注解有没有加上或者是加错,应给是@Service ,注解是否引用了Spring类,不要导成别的包了,看清包的路径。

2,还有就是如果Service层分成了接口和实现类看看实现类有没有加注解(@Service),看看有没有实现类。

3,看看配置文件.xml,有没有启动自动扫描Service所在的包

这几个方案未能解决,难受~

service层实现类:

//service调用dao@Service
public class PlayersServiceImpl implements PlayersService {

    private PlayersMapper playersMapper;
@Autowired
    @Qualifier("playersMapper")
    public void setPlayersMapper(PlayersMapper playersMapper) {
        this.playersMapper = playersMapper;
}

    @Override
public int addPlayer(Players players) {
        return playersMapper.addPlayer(players);
}

    @Override
public int deletePlayer(int id) {
        return playersMapper.deletePlayer(id);
}

    @Override
public int updatePlayer(int id) {
        return playersMapper.updatePlayer(id);
}

    @Override
public List<Players> queryAllPlayer() {
        return playersMapper.queryAllPlayer();
}

    @Override
public Players queryPlayerById(int id) {
        return playersMapper.queryPlayerById(id);
}
}

回答

看着像是mybatis得mapper没有扫描注册成为bean导致得