【踩坑小记】springBoot应用启动报错,变量未找到依赖的实体类

今天,在运行springboot项目遇到了报错,经过研究后终于发现了坑在哪里,记录以下,避免再次踩坑。

***************************

APPLICATION FAILED TO START

***************************

Description:

Field roleMapper in com.onezero.springboottest.service.impl.RoleServiceImpl required a bean of type 'com.onezero.springboottest.mapper.RoleMapper' 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.onezero.springboottest.mapper.RoleMapper' in your configuration.

虽然说注解都没有遗漏,都添加到指定的地方,但是在运行应用时仍然报错,报错信息如下:

Field roleMapper in com.onezero.springboottest.service.impl.RoleServiceImpl required a bean of type 'com.onezero.springboottest.mapper.RoleMapper' that could not be found.

The injection point has the following annotations:

- @org.springframework.beans.factory.annotation.Autowired(required=true)

翻译过来就是:

com.onezero.springboottest.service.impl.RoleServiceImpl中的变量roleMapper没有找到依赖的一个com.onezero.springboottest.mapper.RoleMapper类型的实体类。

研究之后发现,问题出在引入的依赖上,注意引入的依赖是mybatis-spring-boot-starter而不是mybatis,所以需要将pom.xml文件中引入的依赖做下修改,引入新的mybatis-spring-boot-starter依赖.

 

<!--<dependency>-->
    <!--<groupId>org.mybatis</groupId>-->
    <!--<artifactId>mybatis</artifactId>-->
    <!--<version>3.4.1</version>-->
<!--</dependency>-->
<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>2.0.1</version>
</dependency>

修改之后在试着去重启应用,发现启动成功了!

顺利从坑里出来!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值