小记:idea中springboot无法自动装配Could not autowire. No beans of 'UserMapper' type found. more...
2019-03-27 18:55
786 查看
版权声明:标明原创的版权均归本人所有,任何人或团体、机构全部转载或者部分转载、摘录,请保留本博客链接或标注来源. https://blog.csdn.net/weixin_41935702/article/details/88852598
问题如图所示
如果你遇到的情况也是这样,下面的步骤将带你快速出坑
方案一
在自动转配的注解后面添加(required=false)
@Autowired(required=false) public UserMapper userMapper;
当我们在使用@Autowired注解的时候,默认required=true,表示注入的时候bean必须存在,否则注入失败。
方案二
效果如图所示
方案三
在UserMapper上面添加
@Component(value =“userMapper”)
虽然能解决红线的问题,
@Component注解,表明当需要创建类时,这个被注解的类是一个候选类。相当于类交给Spring管理,重新起个名字叫userMapper,但是并不推荐这样做。
在SpringBoot中集成MyBatis,可以在mapper接口上添加@Mapper注解,将mapper注入到Spring。但是如果每一给mapper都添加@mapper注解会很麻烦!!!
这时可以使用@MapperScan注解来扫描包。
所以,一般在Application上面标注了MapperScan,如图所示。
相关文章推荐
- idea中mybatis+spring boot, mapper 提示Could not autowire. No beans of … type found解决办法
- IDEA引入dao接口,Could not autowire. No beans of 'UserMapper' type found
- idea 出现Could not autowire. No beans of 'xxxxMapper' type found. 安装 Mybatis Plugin 插件
- Could not autowire. No beans of 'UserMapper' type found.
- Could not autowire. No beans of 'UserMapper' type found.
- Idea的spring工程里,经常会遇到Could not autowire. No beans of 'xxxx' type found的错误提示
- 解决 IntelliJ IDEA Could not autowire. No beans of 'xxxx' type found 问题
- Idea 解决 Could not autowire. No beans of 'xxxx' type found 的错误提示
- mapper提示Could not autowire. No beans of … type found?
- mapper提示Could not autowire. No beans of … type found?
- mybatis+spring boot, mapper 提示Could not autowire. No beans of … type found
- Could not autowire. No beans of 'FilesMapper' type found.报错
- Could not autowire. No beans of 'xxxMapper' type found.
- Could not autowire. No beans of 'XXXService' type found. more...
- mybatis+spring boot, @Autowired 提示Could not autowire. No beans of … type found
- IntelliJ Idea取消Could not autowire. No beans of 'xxxx' type found的错误提示
- Could not autowire. No beans of 'xxx' type found 的错误提示处理方式
- Could not autowire. No beans of 'xxxx' type found的错误提示(IntelliJ Idea)
- Could not autowire. No beans of 'xxxx' type found
- IDEA下Spring项目报错-could not autowire. no beans of“” type found