springboot 使用@Autowired注入Mapper 报错

springboot 使用@Autowired注入Mapper 报错 但是启动没问题,也可以正常访问,请求数据.
报错:

clipboard.png

Service层

@Service
@Transactional
public class AccountService {
    @Autowired
    private AccountMapper accountMapper;

    public int add(String name, double money) {
        return accountMapper.add(name, money);
    }

mapper

@Mapper
public interface AccountMapper {

    @Insert("insert into account(name, money) values(#{name}, #{money})")
    int add(@Param("name") String name, @Param("money") double money);
}

刚接触Springboot,整合MyBatis也是跟着教程走的...一起学的小伙伴,同样也报错,但是他就启动报错....

阅读 16.9k
4 个回答

idea的检查spring bean的机制,并不影响使用

新手上路,请多包涵

楼主你的问题是怎么解决的?我遇到了和你的一模一样的问题,求解答,谢谢!

新手上路,请多包涵

只需要在Mapper接口上加上@Component注解即可。

@Autowired 直接换成 @Resource 注解即可。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题