springboot service.impl.PtablServiceimpl required a bean of type ‘com.four.numfour.Ptablemapper

本文深入解析了Spring框架中出现的bean注入失败问题,具体表现为在PtableServiceimpl中无法找到所需的PtableMapper bean。文章探讨了可能的原因,包括未正确配置@Repository、@Service或@ComponentScan与@MapperScan注解,并提供了相应的解决策略。

修改前

修改后

报错:
Description:

Field ptableMapper in com.four.numfour.service.impl.PtableServiceimpl required a bean of type 'com.four.numfour.dao.PtableMapper' 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.four.numfour.dao.PtableMapper' in your configuration.

翻译:

描述:

com.four.numfour.service.impl.PtableServiceimpl中的字段ptableMapper需要一个无法找到的类型为'com.four.numfour.dao.PtableMapper'的bean。
注入点具有以下注释:
 -  @ org.springframework.beans.factory.annotation.Autowired(required = true)


行动:

考虑在配置中定义类型为'com.four.numfour.dao.PtableMapper'的bean。

从错误中个可以看到是未扫描到包,这种情况可以分为 一下几种

1. dao没有配置@Repository

2. serviceimpl没配置@Service

3.@ComponentScan(basePackages = {"com.four.numfour"})    和 @MapperScan("com.four.numfour.dao")

导致以上报错是因为没配置@MapperScan("com.four.numfour.dao") 后面加上就启动正常并能访问index


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值