当前位置: 代码网 > it编程>编程语言>Java > Springboot项目启动失败提示找不到dao类的解决

Springboot项目启动失败提示找不到dao类的解决

2025年08月01日 Java 我要评论
***************************application failed to start***************************description:field p

***************************
application failed to start
***************************

description:

field productdao in com.yj.inventorymanagement.service.impl.productserviceimpl required a bean of type 'com.yj.inventorymanagement.dao.productdao' that could not be found.

the injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.autowired(required=true)

action:

consider defining a bean of type 'com.yj.inventorymanagement.dao.productdao' in your configuration.

错误描述

项目里明明已经写了dao类,却还是提示xxxdao类notfound。

原因

没有注入dao类。

解决方法

可以在这个dao类上加上@mapper注解,也可以在整个项目的启动类xxxapplication加上@mapperscan(basepackages="dao类所在的包路径"),推荐第二种方式注入dao,因为项目的dao类不止一个,这样就不用一个一个dao文件去加@mapper,可以做到一劳永逸。

@springbootapplication
@mapperscan(basepackages = "com.yj.inventorymanagement.dao")
public class inventorymanagementapplication {

	public static void main(string[] args) {
		springapplication.run(inventorymanagementapplication.class, args);
	}

}

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com