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

By | 7月 5, 2020

今天,在运行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>

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

顺利从坑里出来!

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

  1. dublaj

    You should take part in a contest for one of the highest quality websites online. Joann Eduard Zachariah

    Reply

发表评论

您的电子邮箱地址不会被公开。