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

文章描述了一个SpringBoot应用程序在启动时遇到的问题,即无法找到ProductDao类型的bean。解决方案是使用@Mapper注解标记DAO类,或者在启动类上使用@MapperScan注解指定包含DAO类的包,以进行自动扫描和注入。推荐使用@MapperScan,特别是当项目中有多个DAO类时。
摘要由CSDN通过智能技术生成

***************************
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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值