显示mapper扫描不到的错误

编程入门 行业动态 更新时间:2024-10-10 09:20:24

显示mapper扫描不到的<a href=https://www.elefans.com/category/jswz/34/1771449.html style=错误"/>

显示mapper扫描不到的错误

学springboot,开始搭建一个项目,但是一直显示mapper扫描不到的错误:


“Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘userController’: Unsatisfied dependency expressed through field ‘userMapper’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.minibike.bike.user.dao.UserMapper’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}”

“Field userMapper in com.minibike.bike.user.controller.UserController required a bean of type ‘com.minibike.bike.user.dao.UserMapper’ that could not be found.”

于是在网上找解决方案,都是治标不治本,不得不说现在的博客质量下降的厉害,太误导人了,打开好多个都是一样的内容,难道没人遇到的错误一样,连包名和类名也一样吗?有的人抄别人博客,类名和包名都懒得换一下?

最后解决方案是在Application.java主类上加注解@MapperScan(“com.minibike.bike.user.dao”)。括号中引号里边是mapper所在包路径。

加上注解后不再报错,也能正常输出oooo

第一次接触springboot,昨天下午到今早一直没找到问题所在,后来查文档、注解,然后不断尝试,最后终于解决。

当然这个只是我个人项目开发中遇到的问题解决办法,不一定通用,但是如过遇到这样的问题,也可以一试。

更多推荐

显示mapper扫描不到的错误

本文发布于:2024-03-09 18:57:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1725813.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   mapper

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!