@Autowired Could not autowire


@Autowired Could not autowire


1 简介

在使用Intellij IDEA时,springboot整合mybatis在IndexController类中有如下的代码:

public class IndexController {
        @Autowired
        private LeaveMapper;
}

用@Autowire注解完成属性装配
@Autowire注解和@Resource一样,同样也可以标注在字段或属性的setter方法上,但它默认按类型装配。但是在添加了@Autowired注解之后,private LeaveMapper leaveMapper;下面就标识了红色的波浪线提示错误了,该如何解决该问题呢?

2 问题描述

通过点击红色leaveMapper,可以得到如下的提示:

Could not autowire. No beans ofLeaveMappertype found.(Ctrl + F1)
Checks autowiring problems in a bean class.

之前通过查询网上,查找解决方案,找到一种说法:即在程序结构中,可以通过快捷键Ctrl + Alt + Shift + S,一键到达,然后点击Facets移除Spring检测。但这种方式其实是有问题的,不建议采用

3 解决方式

点击IntelliJ IDEA设置[Ctrl + Alt + S],直接在搜索栏中搜索autowiring for Bean Class,直接去掉该项勾选即可。
逐级查找如下:

File—>settings—>Editor—>Inspections—>Spring—>Spring Core—>Code—>Autowiring for Bean Class

去掉勾选项,然后选择Apply和OK确认即可解决leaveMapper波浪线问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值