Field XXX required a bean of type XXX that could not be found.

springboot 启动报错required a bean of type ‘com.dexin.base.BaseMapper’ that could not be found
****Description:

Field userTextMapper in com.springboot.demo.service.UserTextService required a bean of type ‘com.springboot.demo.dao.UserTextMapper’ that could not be found.

Action:

Consider defining a bean of type ‘com.springboot.demo.dao.UserTextMapper’ in your configuration.****

搜了很多文章都没解决,后来通过分析原理发现,造成spring没注册成功Bean的原因有一下几种!

1.包结构的问题。

项目启动时,只有@SpringBootApplication 所在的包被扫描,也就是只扫码启动类MainApplication.java所在的这个包,需要将启动类放在外层包,跟controller、dao、service同级

2.没有自动注入导致。

你的service类上面没有@service注解或者mapper上没有@mapper注解,但是这种情况比较少见,一般不会忘记。

3.配置了mybatis,但没有指定扫描的包。(很大可能)

**方法:**启动类加注释:@MapperScan(basePackages = { “mapper所在的包路径” }, sqlSessionFactoryRef = “sqlSessionFactory”),表示扫描xx.xx.mapper包下的所有mapper。 如有多个Mapper,@MapperScan(basePackages = { “Mapper1” ,“Mapper2”,“Mapper3”}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值